按唯一计数进行不同计数和求和
我有一个包含教程的表(tutorial_id、user_id、tutorial_date),我的任务是找出有多少用户完成了特定数量的教程。
因此,如果有 5 个用户完成了 6 个教程,3 个用户完成了 2 个教程,我想要以下输出:
Tutorial_Count (unique) Number of Students With this Tutorial Count
6 5
2 3
我可以获得不同的计数(第一列):
SELECT DISTINCT COUNT(user_id) from tutorials group by user_id
但我不知道如何计算数量符合这些计数括号的用户数。
I've got a table with tutorials (tutorial_id,user_id,tutorial_date) and I'm tasked with finding out how many users did a particular number of tutorials.
So, if there were 5 users who did 6 tutorials, and 3 users who did 2 tutorials, I'd want the following output:
Tutorial_Count (unique) Number of Students With this Tutorial Count
6 5
2 3
I can get the distinct counts (first column):
SELECT DISTINCT COUNT(user_id) from tutorials group by user_id
But I don't know how to count the number of users who fit into those count brackets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
未经测试,但试试这个:
Untested, but try this: