ROW_NUMBER() OVER (order by 列名 desc ):对列名进行降序排序,然后加一列为显示每行的行数
select * into #t2 from (select [Time],[Operator],[Data],ROW_NUMBER() OVER(order by [Data])as ROWS from [dbo].[Test_1]) as ff
select * from #t2
运行结果:
分组排序
select * into #t3 from (select [Time],[Operator],[Data],ROW_NUMBER() OVER(partition by [Time] order by [Data])as ROWS from [dbo].[Test_1]) as ff
select * from #t3
运行结果: