zoukankan      html  css  js  c++  java
  • The difference for ROW_NUMBER/RANK/DENSE_RANK/NTILE

    USE tempdb
    GO
    CREATE TABLE Table1
    (
    ID INT IDENTITY(1,1) NOT NULL,
    UserID INT NOT NULL
    )
    GO
    INSERT INTO Table1(UserID)
    SELECT 1
    UNION ALL
    SELECT 1
    UNION ALL
    SELECT 3
    UNION ALL
    SELECT 4
    UNION ALL
    SELECT 5
    GO

    SELECT
    UserID
    ,ROW_NUMBER()OVER(ORDER BY UserID) AS RowNumberID
    ,RANK()OVER(ORDER BY UserID) AS RankID
    ,DENSE_RANK()OVER(ORDER BY UserID) AS DenseRankID
    ,NTILE(3)OVER(ORDER BY UserID) AS NtileID
    FROM Table1
    SELECT
    UserID
    ,ROW_NUMBER()OVER(ORDER BY UserID) AS RowNumberID
    ,RANK()OVER(ORDER BY UserID) AS RankID
    ,DENSE_RANK()OVER(ORDER BY UserID) AS DenseRankID
    ,NTILE(3)OVER(ORDER BY UserID) AS NtileID
    FROM Table1

    结果:


     

  • 相关阅读:
    11.26
    数组
    JavaScript
    2018.11.26
    input标签
    HPH 函数
    jQuery
    19/1/3数组
    2018/12/26//循环体
    12/25
  • 原文地址:https://www.cnblogs.com/TeyGao/p/2339306.html
Copyright © 2011-2022 走看看