当前的SQL语句:
SELECT count(installUserID) as userCount
FROM installUsers
group by installationID
电流输出:
userCount
4
2
1
1
1
2
4
1
3
1
我正在尝试计算
userCount
是1的次数以及2的次数...所需输出示例:
userCount = 1, 5 times
userCount = 2, 2 times
userCount = 3, 1 times
userCount = 4, 2 times
我环顾了互联网,我想我可以使用聚合函数(也许使用
grouping
)来做些事情,但是我仍然不清楚如何使用纯sql实现此功能。 最佳答案
看来您想要计数。为此,您可以使用外部选择:
SELECT userCount, COUNT(*) AS userCountcount
FROM
(
SELECT COUNT(installUserID) as userCount
FROM installUsers
GROUP BY installationID
) AS T1
GROUP BY userCount
ORDER BY userCount
关于sql - 按计数进一步分组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11800915/