zoukankan      html  css  js  c++  java
  • Hive中的Row_Number()使用

    语法:row_number() over (partition by 字段a order by 计算项b desc ) rank 

    --这里rank是别名

    partition by:类似hive的建表,分区的意思;

    order by :排序,默认是升序,加desc降序;

    这里按字段a分区,对计算项b进行降序排序

    实例:

    要取top10品牌,各品牌的top10渠道,各品牌的top10渠道中各渠道的top10档期 

    1、取top10品牌

    select 品牌,count/sum/其它() as num  from table_name order by num limit 10;

     2、 取top10品牌下各品牌的top10渠道        

    select 

              a.*

    from

              (

                      select 品牌,渠道,count/sum/其它() as num row_number() over (partition by 品牌 order by num desc ) rank  

                       from table_name

                       where 品牌限制条件

                       group by 品牌,渠道

              )a

    where 

              a.rank<=10

     3、 取top10品牌下各品牌的top10渠道中各渠道的top10档期

    select 

              a.*

    from

              (

                      select 品牌,渠道,档期,count/sum/其它() as num row_number() over (partition by 品牌,渠道 order by num desc ) rank  

                       from table_name

                       where 品牌,渠道 限制条件

                       group by 品牌,渠道,档期

              )a

    where 

              a.rank<=10

  • 相关阅读:
    csu1804
    uvalive4513
    poj3264(Sparse-Table 算法模板)
    uva11107(后缀数组)
    poj2774(最长公共子串)
    uvalive4108(线段树)
    hdu5306 Gorgeous Sequence
    bzoj2823: [AHOI2012]信号塔&&1336: [Balkan2002]Alien最小圆覆盖&&1337: 最小圆覆盖
    bzoj3330: [BeiJing2013]分数
    bzoj1283: 序列
  • 原文地址:https://www.cnblogs.com/peizhe123/p/9668455.html
Copyright © 2011-2022 走看看