首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

亟需一个SQL排名

2013-11-15 
需要一个SQL排名通过下列SQL取得了一组数据select count(*) as count, fileName as name from table where

需要一个SQL排名
通过下列SQL取得了一组数据
select count(*) as count, fileName as name from table where type = 'a01' group by fileName order by count desc

count      name
 25         jk
 23         wtt
 19         f9
 17         wy
 13         jqq
 10         alk



现在我需要加一个排名,期望能得到下面的效果
count      name    rank
 25         jk      1
 23         wtt     2
 19         f9      3
 17         wy      4
 13         jqq     5
 10         alk     6

求教sql的写法。谢谢!

[解决办法]
RANK() 相同排名后也有跳过。
DENSE_RANK() 相同排名不跳过。


select count(*) as count, 
       fileName as name,
       rank over(order by count(*)) as rank
  from table
 where type = 'a01'
 group by fileName
 order by count desc


select count(*) as count, 
       fileName as name,
       dense_rank over(order by count(*)) as dense_rank
  from table
 where type = 'a01'
 group by fileName
 order by count desc

[解决办法]
select count(*) as count, fileName as name,row_number()over(order by count(*) desc ) from table where type = 'a01' group by fileName 

热点排行