赤青1

那些我们丢失的美好!是我们永远的遗憾与记忆

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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
posted on   赤青1  阅读(5854)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示