Id Desc Sequenceno
-----------------------------
84 TEST 1
84 TEST2 2
84 TEST3 3
85 IPhone 1
85 IPhone1 2
87 Nokia 1
88 Vivo 1
88 Vivo1 2
我有Id
和Desc
列。如何获得上面的Sequenceno
列?
先谢谢。
答案 0 :(得分:4)
使用ANSI标准row_number()
函数:
select t.*, row_number() over (partition by id order by [desc]) as seqnum
from t;
答案 1 :(得分:1)
试试这个:
SELECT
Id, [Desc],
ROW_NUMBER() OVER (PARTITION BY Id ORDER BY Id) AS Sequenceno
FROM #Temp;