我有这张桌子:
GROUP_CONCAT(DISTINCT mytable.gloss) AS gloss
...
GROUP BY mytable.entry
返回:
如何以这种方式得到结果-按入口和意义分组并用分号';'分隔 符号?'
我有这张桌子:
GROUP_CONCAT(DISTINCT mytable.gloss) AS gloss
...
GROUP BY mytable.entry
返回:
如何以这种方式得到结果-按入口和意义分组并用分号';'分隔 符号?'
首先,分组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