zoukankan      html  css  js  c++  java
  • hive_连续天次计算

    drop table sospdm.tmp_yinfei_yuanzuan_redbag;
    create table sospdm.tmp_yinfei_yuanzuan_redbag stored as rcfile as
    select member_no,red_amount,process_time as min_date,date_add(process_time,diffdate-1) as max_date,diffdate from 
    (
        select member_no,red_amount,process_time,diffdate,row_number() over(partition by member_no order by diffdate desc ) as rk 
        from 
        (
            select
                 member_no,red_amount,process_time,diffdate
                ,row_number() over(partition by member_no,red_amount,process_time order by diffdate) as rn
            from 
            (
                select 
                     t1.member_no,t1.red_amount,t1.process_time,datediff(t2.process_time,t1.process_time)+1 as diffdate
                from 
                (
                    select member_no,sum(red_amount) as red_amount,to_date(process_time) as process_time
                    from sosp_ssa.xxx
                    where to_date(process_time)>='2018-12-20' and to_date(process_time)<='2019-01-20' and activity_id = '1212draw'
                    group by member_no,to_date(process_time)
                ) t1 
                inner join
                (
                    select member_no,sum(red_amount) as red_amount,to_date(process_time) as process_time
                    from sosp_ssa.xxx
                    where to_date(process_time)>='2018-12-20' and to_date(process_time)<='2019-01-20' and activity_id = '1212draw'
                    group by member_no,to_date(process_time)
                ) t2
                on t1.member_no=t2.member_no
                where datediff(t2.process_time,t1.process_time) >= 0
            ) t3
        ) t4 where diffdate = rn and rn >= 7
    ) t5 where rk = 1;
  • 相关阅读:
    乌龟git
    CI的model层的操作
    排序算法
    linux安装教程
    linux命令Netstat
    linux压缩和解压缩
    标准库模块time,datetime
    为什么计算机时间和众多编程语言要从1970年1月1日开始算起
    模块和包的导入
    Python封装应用程序的最佳项目结构是什么?
  • 原文地址:https://www.cnblogs.com/yin-fei/p/10752043.html
Copyright © 2011-2022 走看看