2016-02-01 28 views
0

使用count(*)以上(按....順序)獲得連續排名我有表如何在Oracle

Item 
------ 
apple 
apple 
bean 
bean 
cherry 
cherry 
cherry 

我想創建另一個表項的排名像這樣下面

Item ranking 
---------------- 
apple  1 
apple  1 
bean  2 
bean  2 
cherry  3 
cherry  3 
cherry  3 

我用的語句,並能生成排名這樣

選擇項目,從表中的

COUNT(*)以上(按項目順序)
Item ranking 
---------------- 
apple  1 
apple  1 
bean  3 
bean  3 
cherry  5 
cherry  5 
cherry  5 

有沒有一種快速的方法來創建所需的連續排名?

非常感謝!

回答

2

嘗試DENSE_RANK功能:

select item, dense_rank() over (order by item) from table a 
+0

感謝了很多!有用 –