如何计算组返回的组的数量?

编程入门 行业动态 更新时间:2024-10-24 12:28:23
本文介绍了如何计算组返回的组的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 select count(*) as count from table group by foreign_id order by count

这会返回每个外部标识的匹配数。

This returns a number of matches for each foreign id. However what im looking for is to summarise the results.

所以结果是:

10 results grouping 1 elements 5 results grouping 2 elements 7 results grouping 7 elements

推荐答案

好的,得到了​​。问题的标题比问题本身更好:)

Ok, got it. The title of the question expainls it better than the question itself :)

您需要先知道每个FK出现的次数:

You need to first know how many times each FK appears:

select count(*) as GroupAmount from t1 group by foreign_id

一旦你有了这一点,你必须分组,得到每个项目出现的次数与上述相同的方式。这将导致:

Once you have this, you have to group them to get the amount of times each item appears the same way as above. This will result in:

select GroupAmount, count(*) GroupAmountTimes from ( select count(foreign_id) as GroupAmount from t1 group by foreign_id ) as SubQuery group by GroupAmount

查看操作此处

更多推荐

如何计算组返回的组的数量?

本文发布于:2023-11-12 12:42:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581522.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数量

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!