Top 5
状态。
例如
Id City State
1 Mumbai Maharashtra
2 Pune Maharashtra
3 Amritsar Punjab
这里我期望的输出是作为具有count
的状态的名称State_Name count
Maharashtra 2
Punjab 1
SELECT p.name, count(pr.State) FROM City pr
join state p on p.Id = pr.StateId;
答案 0 :(得分:1)
将Group by
与count
汇总一起使用来统计state
并使用Limit
来过滤记录
select count(1) Cnt,state
from yourtable
group by state
order by Cnt desc Limit 5