zoukankan      html  css  js  c++  java
  • hive 分组排序,topN

                                            hive 分组排序,topN

    语法格式:row_number() OVER (partition by COL1 order by COL2 desc ) rank
    partition by:类似hive的建表,分区的意思;
    order by :排序,默认是升序,加desc降序;
    rank:表示别名
    表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的)

    -- 分组排序
    -- 求某用户日期最大的3天
    select a.* from(
    select p_day,muuid,row_number() over(partition by muuid order by p_day) rank
    from test
    group by p_day,muuid)a
    where a.rank <=3;
    ---- 获取每天充值数的前3名
    select * from(
    select p_day,muuid,c row_number over(partition by p_day order by p_day,c desc) ord
    from(
    select p_day,muuid,count(1) c from test where p_day>'2017-09-09'
    group by p_day,muuid
    ) t1
    )t2
    where ord <= 3;

  • 相关阅读:
    创建pdf
    IOS绘图
    IOS断点续传
    IOS程序之间的跳转
    MBProgressHUD的使用
    清除缓存的方法(计算)
    使用post请求下载数据
    NSTimer的使用
    定位功能(使用系统地图)
    fork仓库保持同步更新
  • 原文地址:https://www.cnblogs.com/yyy-blog/p/6912336.html
Copyright © 2011-2022 走看看