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

       最终结果

      

      

      

      

       

      



  • 相关阅读:
    set的使用
    this.$watch(),this.$set(),this.$nextTick()=>{})
    web 错误代码解析
    samba 问题解决
    Linux postfix配置方法
    Linux rhcsa认证考试试题模拟
    Linux 使用nmcli配置网络
    Linux 链路聚合
    Linux ISCSI服务配置
    Linux Apache配置https访问
  • 原文地址:https://www.cnblogs.com/yaboya/p/9303407.html
Copyright © 2011-2022 走看看