zoukankan      html  css  js  c++  java
  • 12_Hive实战案例_累计报表_级联求和

    注:Hive面试题:累积报表

    数据文件:

      有如下访客访问次数统计表 t_access_times

      

      需要输出报表:t_access_times_accumulate

      

    实现步骤:

      创建表,并将数据加载到表中:

      

      1、第一步,先求每个用户的月总金额

      

      

      2、第二步,将月总金额表 自己连接自己

      

      3、第三步,从上一步的结果中:进行分组查询,分组的字段是a.username a.month
                      求月累计值:将b.month <= a.month的所有b.salary求和即可

      

    select A.username,A.month,max(A.salary) as salary,sum(B.salary) as accumulate
    from 
    (select username,month,sum(salary) as salary from t_access_times group by username,month) A 
    inner join 
    (select username,month,sum(salary) as salary from t_access_times group by username,month) B
    on
    A.username=B.username
    where B.month <= A.month
    group by A.username,A.month
    order by A.username,A.month;
    View Code

       最终结果

      

      

      

      

       

      



  • 相关阅读:
    C# 批量图片合并工具(附源代码)
    C# 封装
    SQL语句基础
    c# My计算器源码
    炸酱面
    烧茄子
    Linux Desktop Entry 文件深入解析
    硬盘安装ubuntu
    使用C语言进行面向对象的开发--GObject入门[2]
    GObject对象系统 (1)
  • 原文地址:https://www.cnblogs.com/yaboya/p/9303407.html
Copyright © 2011-2022 走看看