gpt4 book ai didi

MYSQL:分组依据和计数问题

转载 作者:行者123 更新时间:2023-11-29 19:37:58 25 4
gpt4 key购买 nike

我已经研究过这个问题,但找不到解决方案。

enter image description here

如何获得这样的输出?

enter image description here

最佳答案

您可以将原始表连接到一个子查询,该子查询统计每所学校就读的学生。

SELECT t1.student,
t2.count,
t1.school
FROM yourTable t1
INNER JOIN
(
SELECT school, COUNT(*) AS count
FROM yourTable
GROUP BY school
) t2
ON t1.school = t2.school
ORDER BY t2.count DESC,
t1.school

请注意,问题中并不清楚您的预期顺序。您可能一直在寻找以下顺序:

ORDER BY t1.school,
t1.count -- or t2.count DESC

关于MYSQL:分组依据和计数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41477981/

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