Ich habe 2 Tabellen wie folgt aus:
Tabelle a:GROUP_CONCAT DISTINCT BY ID
ID type
1 1
1 1
2 1
2 2
2 2
3 2
Tabelle b:
ID name
1 a
2 b
3 b
Und erwartete Ergebnis:
ID type name
1,2 1 a,b
2,3 2 b,b
ich versucht habe, :
SELECT GROUP_CONCAT(DISTINCT ID), a.type,
GROUP_CONCAT(SELECT name FROM b WHERE ID = a.ID)
FROM a GROUP BY a.type
aber es funktioniert nicht. Ich brauche den Namen GROUP_CONCAT und DISTINCT nach ID.
Es wird zurück: ID ((1,2), (2,3)), Typ ((1), (2)), Name ((a, b), (b)) –
das Problem ist, dass Sie die 'b, b' für Typ = 2 brauchen? Was genau bedeutet das dort? Was gruppierst du nach dieser Spalte? – Dekel
Ja, ich brauche genau b, b für Typ = 2. Es ist nur ein Beispiel für mein Problem. Ich habe eine Lösung gefunden: SELECT GROUP_CONCAT (DISTINCT a.id), a.type, (SELECT GROUP_CONCAT (Name) FROM b WHERE FIND_IN_SET (ID, GROUP_CONCAT (a.ID))) VON einer GROUP BY a.type –