sqlserver 2000/2005/2008中一句话完成分组后加序号,挺实用的单行sql,供大家学习参考。
复制代码代码如下:
--SQL SERVER 2005/2008
select row_number() over (partition by col order by id) as num,col from @T
结果:
复制代码代码如下:
--SQL SERVER 2000
select (select count(1) from @T where col=t.col and id<=t.id) as num ,col from @T t
结果: |