sqlserver中有几种排序的方式
1、order by asc||desc 【默认值升序(asc)、降序:desc】
列:select * from tb order by id
2、ROW_NUMBER() over(partition by columnname order by columnname)函数可以用于查询重复数据、去重复查询,删除重复数据 --虚拟自增排序
列:select ROW_NUMBER()over(order by name) as num,* from tb
select ROW_NUMBER()over(partition by name order by name) as num,* from #Tmp --重复数据叠加
3、RANK()over(order by columnname) --跳跃式排序
列:select RANK()over(order by name),* from #Tmp
4、DENSE_RANK()over(order by columnname) --重叠式排序
列:select DENSE_RANK()over(order by name),* from #Tmp
5、NTILE()OVER(ORDER BY COLUMNNAME)--将数据平分排序
列:select NTILE(2)over(order by name),* from #Tmp
select NTILE(3)over(order by name),* from #Tmp