2016-10-04 102 views
0
ID  descr points 
---------------------- 
1000 24  100 
1000 24  40 
1000 25  100 
1000 25  40 
2000 24  100 
2000 25  100 
2000 26  100 

以上是我的表格。我想添加/更新列枚舉記錄的基礎上IDdescr。我怎樣才能做到這一點?枚舉多列表中的記錄

以下是我要找的結果。

ID  descr points order# 
------------------------------- 
1000 24  100   1 
1000 24  40   2 
1000 25  100   1 
1000 25  40   2 
2000 24  100   1 
2000 25  100   2 
2000 26  100   3 
+0

什麼SQL產品是您使用?你試過什麼了?你有沒有搜索過Stackoverflow?我很確定這個答案在之前。請參閱http://stackoverflow.com/help/how-to-ask –

+0

如果您使用ID和descr,每個ID = 2000的訂單號不會是1嗎? – HKImpact

回答

2

可以使用ANSI標準的功能`ROW_NUMBER():

select id, descr, points, 
     row_number() over (partition by id, descr order by points desc) as ordernum 
from t;