• sqlserver 排序


    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
    学着把生活的苦酒当成饮料一样慢慢品尝, 不论生命经过多少委屈和艰辛, 我们总是以一个朝气蓬勃的面孔, 醒来在每一个早上。
  • 相关阅读:
    valueOf与toString
    责任链模式
    Js中Symbol对象
    Vue路由懒加载
    updatedb命令
    策略模式
    Docker(3)- Centos 7.x 下 Docker 镜像加速配置
    Vmware
    Docker(2)- Centos 7.x 下安装 Docker
    Docker(1)- 什么是 Docker
  • 原文地址:https://www.cnblogs.com/yhm9/p/11318020.html
Copyright © 2020-2023  润新知