zoukankan      html  css  js  c++  java
  • Hive SQL rank()/dense_rank()/row_number()的区别

    SET mapreduce.job.queuename=xxx;
    
    WITH a AS (
    SELECT 'a' col_1, 1 col_2
    union all
    SELECT 'a' col_1, 2 col_2
    union all
    SELECT 'a' col_1, 3 col_2
    ),
    
    b AS (
    SELECT 'a' col_1, 4 col_2
    union all
    SELECT 'a' col_1, 4 col_2
    union all
    SELECT 'a' col_1, 5 col_2
    ),
    
    c AS (SELECT * from a UNION ALL SELECT * FROM b)
    
    SELECT *,
    rank() OVER(PARTITION BY col_1 ORDER BY col_2 DESC) rnk,  -- 排名相等,排名会留出空位
    dense_rank() OVER(PARTITION BY col_1 ORDER BY col_2 DESC) dense_rnk,  -- 排名相等,排名不会留出空位
    row_number() OVER(PARTITION BY col_1 ORDER BY col_2 DESC) row_rnk  -- 直接按照记录值排序,如果两个值相等则随机排
    FROM c;
    

  • 相关阅读:
    离线缓存之RNCachingURLProtocol解析
    Element demo解析
    GHUnit+OCMock
    XCTest+XCTool
    day1`4整理
    day4 笔记
    day3
    day1
    day2
    Python学习(二)——Python基础
  • 原文地址:https://www.cnblogs.com/swordspoet/p/14755960.html
Copyright © 2011-2022 走看看