vendredi 29 janvier 2016

How to SQL group by based on common membership

I have a table like the following, which just say what person is matches someone else on the same team (including yourself):

person1|person2
-------------
A      | A
B      | A
C      | A
A      | B
B      | B
C      | B
A      | C
B      | C
C      | C
X      | X
Y      | X
X      | Y
Y      | Y

I would like to have two records using a GROUP_CONCAT and have the following

team
-------
A, B, C
X, Y

The order of the GROUP_CONCAT is not too important but I don't want repeats like "A, B, C", "B, A, C". Or better yet would settle for just any sort of teamid along with the member:

teamid|person
-------------
1     | A
1     | B
1     | C
2     | X
2     | Y

Aucun commentaire:

Enregistrer un commentaire