Bonjour,

J'ai une table de ce type:

Prof Groupe Etudiant

Prof1 Gr1 Etudiant1
Prof1 Gr1 Etudiant2
Prof1 Gr2 Etudiant3
Prof2 Gr1 Etudiant1
Prof2 Gr1 Etudiant2

En une seule requête je voudrais avoir le résultat suivant (Je concatène les noms des étudiants pour un même prof et un même groupe):

Prof1 Gr1 Etudiant1, Etudiant2
Prof1 Gr2 Etudiant3
Prof2 Gr1 Etudiant1, Etudiant2

J'ai pensé à une requête de ce type:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
select 
	Prof,
	Groupe,
	IF(@ListeEtudiant='', 
		@ListeEtudiant:=test1.Etudiant,
		@ListeEtudiant:=CONCAT(@ListeEtudiant, ", ",test1.Etudiant)
	) as Liste
from Test1, (select @ListeEtudiant='') r
group by 
	Prof,
	Groupe
Mais la requête ne fonctionne pas ...

Elle retourne ceci
"Prof1" "Gr1" "Etudiant1"
"Prof1" "Gr2" "Etudiant1, Etudiant2, Etudiant3"
"Prof2" "Gr1" "Etudiant1, Etudiant2, Etudiant3, Etudiant1"

J'ai donc décide de réinitialiser ma liste à chaque fois que je change de regroupement en faisant ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
select 
	Prof,
	Groupe,
	IF(INSTR(@ListeEtudiant, CONCAT(Prof, Groupe))= 0,
		@ListeEtudiant:=CONCAT("[", Prof, Groupe, "]", test1.Etudiant),
		@ListeEtudiant:=CONCAT(@ListeEtudiant, ", ",test1.Etudiant)
	) as Liste
from Test1, (select @ListeEtudiant:='') r
group by 
	Prof,
	Groupe;
Mais le résultat n'est toujours pas correct
"Prof1" "Gr1" "[Prof1Gr1]Etudiant1"
"Prof1" "Gr2" "[Prof1Gr2]Etudiant3"
"Prof2" "Gr1" "[Prof2Gr1]Etudiant1"


Quelqu'un a une idée (J'utilise MySQL 5.0.27) ?

Merci d'avance