hive、maxcompute计算当月累计、当年累计值示例

2022-11-13 13:07:40 浏览数 (1)

代码语言:javascript复制
select 
     etl_date
    ,sum(order_cnt)      over(partition by etl_month order by etl_date asc) as order_cnt_1m  --当月累计订单量
    ,sum(order_cnt)      over(partition by etl_year order by etl_date asc)  as order_cnt_1y  --当年累计订单量
from (
    select 
         etl_date
        ,substr(etl_date,1,7) as etl_month
        ,substr(etl_date,1,4) as etl_year
        ,sum(order_cnt) as order_cnt --每日订单量
    from order 
    group by etl_date
) t

0 人点赞