1
我有以下查詢:ROW_NUMBER()在分區查詢
declare @temp1 table
(ID1 int not null,
ID2 int not null)
set nocount off
insert into @temp1 values(1453,931)
insert into @temp1 values(1454,931)
insert into @temp1 values(1455,931)
insert into @temp1 values(2652,1101)
insert into @temp1 values(2653,1101)
insert into @temp1 values(2654,1101)
insert into @temp1 values(2655,1101)
insert into @temp1 values(2656,1101)
insert into @temp1 values(3196,1165)
insert into @temp1 values(3899,1288)
insert into @temp1 values(3900,1288)
insert into @temp1 values(3901,1288)
insert into @temp1 values(3902,1288)
--select * from @temp1
select ID1,ID2, ROW_NUMBER() over(partition by ID2 order by ID1) as RowNum1
from @temp1
我現在要做的就是創建一個新的列將組中的所有ID2的together..ie ID2的有931應該有值1在新的專欄中,1101應該有2,1165應該是3,最後所有的1288應該有4 ...我能爲此獲得幫助嗎?
我會做下一次:) –