gpt4 book ai didi

mysql - 有没有办法按出现频率对 mysql 行进行排序?

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

有没有一种方法可以按出现频率对 mysql 行进行排序?

最佳答案

SELECT n, count(*) as freq
FROM your_table
GROUP BY n
ORDER BY freq DESC;

更具体的例子:

SELECT n, count(*) as freq
FROM (
SELECT 1 as n
UNION ALL
SELECT 2 as n
UNION ALL
SELECT 3 as n
UNION ALL
SELECT 3 as n
UNION ALL
SELECT 3 as n
UNION ALL
SELECT 2 as n) as your_table
GROUP BY n
ORDER BY freq DESC;

将返回:

n, freq
3, 3
2, 2
1, 1

关于mysql - 有没有办法按出现频率对 mysql 行进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8515207/

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