gpt4 book ai didi

android - 如何嵌套GROUP_CONCAT?

转载 作者:行者123 更新时间:2023-11-29 21:36:38 25 4
gpt4 key购买 nike

我有这张表:

enter image description here

GROUP_CONCAT(DISTINCT mytable.gloss) AS gloss
...
GROUP BY mytable.entry

返回:

enter image description here

如何这样得到结果——按entry和sense分组,用分号';'分割符号?' enter image description here

最佳答案

首先,按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

关于android - 如何嵌套GROUP_CONCAT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18301411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com