本文介绍了如何计算组返回的组的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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查看操作此处
更多推荐
如何计算组返回的组的数量?
发布评论