我有这张桌子:
GROUP_CONCAT(DISTINCT mytable.gloss) AS gloss
...
GROUP BY mytable.entry
返回:
如何以这种方式获得结果 - 按入口和感觉分组并按分号';'分组标志?'
答案 0 :(得分:2)
首先,按sense
分组:
SELECT entry,
sense,
GROUP_CONCAT(DISTINCT gloss)
FROM mytable
GROUP BY entry,
sense
entry sense gloss
----- ----- ------------
1 1 Orange,Red
1 2 Blue
2 3 Green
2 4 Yellow,Ivory
3 5 Grey
然后对该结果运行另一个GROUP BY
:
SELECT entry,
MIN(sense) AS sense,
GROUP_CONCAT(gloss, ';') AS gloss
FROM (SELECT entry,
sense,
GROUP_CONCAT(DISTINCT gloss) AS gloss
FROM mytable
GROUP BY entry,
sense)
GROUP BY entry
entry sense gloss
----- ----- ------------------
1 1 Orange,Red;Blue
2 3 Green;Yellow,Ivory
3 5 Grey