• SQL Server 排名函数 简单应用


    --排名函数 ROW_NUMBER()  RANK(), DENSE_RANK(),NTILE() 
     

    Over()函数 为排名函数生成排序顺序、
    select ROW_NUMBER() over(order by OrderDate) as Romber,SalesOrderID,OrderDate from SalesLT.SalesOrderHeader ---创建一个单一的排序 SELECT ROW_NUMBER() OVER(partition by year(OrderDate),Month(OrderDate) order by orderdate) as rownumber, SalesOrderID,OrderDate,ShipMethod FROM SalesLT.SalesOrderHeader WHERE SalesOrderID>=280 ORDER BY OrderDate; ---ROW_NUMBER() SELECT rowNumber ,SalesOrderNumber SalesOrderID,OrderDate from ( select ROW_NUMBER() over(order by orderdate,SalesOrderID) as rowNumber,* from SalesLT.SalesOrderHeader where SalesOrderID>293 ) as Q where rowNumber between 21 and 40 order by rowNumber; --Rank() DENSE_RANK() EG:例如 张三跟王五 都是第二名 那么他们的Rank的值应为2 select productID,COUNT(*) as 'Count' from SalesLT.SalesOrderDetail group by ProductID order by COUNT(*); select Productid,salescount,RANK() over(order by salescount) as 'Ranks', DENSE_RANK() OVER(ORDER BY salescount) AS 'Dense_rank' from (select ProductID,COUNT(*) as salescount from SalesLT.SalesOrderDetail group by ProductID) as Q group by 'Ranks';

    运行结果:对比
    通过 对比:Rank的结果与 DeseRank的结果不一样。。
  • 相关阅读:
    DRF简易了解
    Restful API接口规范
    Python分页
    vue笔记(一)
    CNN实现手写数字识别
    深度学习框架Keras
    NLP自然语言处理
    深度学习框架Tensorflow
    维度的区分
    矩阵求导
  • 原文地址:https://www.cnblogs.com/w2011/p/3011393.html
Copyright © 2020-2023  润新知