gpt4 book ai didi

mysql - group_concat 不适用于计数

转载 作者:行者123 更新时间:2023-11-29 18:19:08 27 4
gpt4 key购买 nike

我用的是

SELECT 
GROUP_CONCAT(DISTINCT `a`.`IDperson` SEPARATOR ', ') AS `person`,
COUNT(`a`.`IDjobs`) AS `total`
FROM
`a`
GROUP BY `a`.`ID_person`
ORDER BY `total` DESC

我需要的是得到像这样的结果

person        total
2342 98
1342 75
3844 70
1705 62
3309 53
5918, 1328 52
1503, 1890 46
21004, 6536 45

但是没用它返回的结果就像 GROUP_CONCT 无法正常工作

    person        total
2342 98
1342 75
3844 70
1705 62
3309 53
5918 52
1328 52
1503 46
1890 46
21004 45
6536 45

最佳答案

似乎您需要按计数数量进行连续灌浆,因此您应该

select GROUP_CONCAT(DISTINCT t.IDperson SEPARATOR ', ') AS person,  t.total
from (
select DISTINCT a.IDperson as IDPerson, COUNT(a.IDjobs) AS `total`
FROM a
GROUP BY a.ID_person ) t
group by t.total
ORDER BY t.total DESC

关于mysql - group_concat 不适用于计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46747064/

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