Count, order desc and select top 5

﹥>﹥吖頭↗ 提交于 2019-12-05 05:14:35

In SQL Server you can use TOP to select a certain number of rows along with an order by to get the proper records:

select top 5 type, count(*) Total
from yourtable
group by type
order by total desc

See SQL Fiddle with Demo

select * from (
    select type, count(*) 
    from table
    group by type
    order by 2 desc
)
where rownum <=5
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!