gpt4 book ai didi

mysql - 计算出现次数最多的字符串

转载 作者:行者123 更新时间:2023-11-29 13:17:22 25 4
gpt4 key购买 nike

例如,我有一张 table :

Names  Details
--------------
wilson admin
david member
wilson admin
wilson admin
sam member
david member

现在我想要实现的是显示这样的表格

Names  Details count
--------------------
wilson admin 3
david member 2
sam member 1

我想根据名字出现的次数来显示

最佳答案

SELECT Name, Detail, COUNT(*) as Count
FROM MyTable
GROUP BY Name, Detail
ORDER BY Count DESC;

由于输出表 SELECT 中有不止一列,因此应按两列进行分组。

关于mysql - 计算出现次数最多的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21298281/

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