sql server 中的 row_number
代码
declare @a table(id int ,name varchar(50))
insert into @a (id,name)
select '1','a'
union all
select '1','a'
union all
select '2','n'
union all
select '2','n'
union all
select '2','n'
union all
select '3','b'
union all
select '3','b';
with b as(
SELECT ROW_NUMBER() OVER ( PARTITION BY id,name ORDER BY id) AS rcount,* FROM @a
)
select * from b
insert into @a (id,name)
select '1','a'
union all
select '1','a'
union all
select '2','n'
union all
select '2','n'
union all
select '2','n'
union all
select '3','b'
union all
select '3','b';
with b as(
SELECT ROW_NUMBER() OVER ( PARTITION BY id,name ORDER BY id) AS rcount,* FROM @a
)
select * from b
继续追寻。。。。。。