如何在sql中给Rank

时间:2013-12-07 10:34:00

标签: sql oracle rank

select * from (select sum(dpt_no) as numbers from department group by dpt_name) order by numbers desc

结果:

  NUMBERS
----------
       420 
       209 
       106 
       105 
       103 
       102 

如何给这个结果排名?

1 个答案:

答案 0 :(得分:2)

请尝试:

select 
    numbers,
    rank() over(order by numbers desc) Rank
from (
    select sum(dpt_no) as numbers 
    from department group by dpt_name
) 
order by numbers desc

样品:

select 
  Col,
  rank() over(order by Col desc) Rank
From YourTable

SQL Fiddle Demo