栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

hive sql里全量表如何计算上月累积,本月累积值

hive sql里全量表如何计算上月累积,本月累积值

hive里假设:dws_store_install_ds 为历史安装全量表
dws_store_install_dm为天增量表
如下逻辑是 计算上月累积,本月累积值 的逻辑

INSERT  OVERWRITE TABLE dws_store_install_ds (pt_d='$date')
SELECt 
IF(t2.app_id  is null ,t1.app_id,t2.app_id)                                  AS app_id
,NVL(install_cnt,0)                                                          AS install_cnt
,NVL(sum_install_cnt,0)+NVL(install_cnt,0)                                   AS sum_install_cnt
,IF(dayofmonth('$date')='1',this_month_install_cnt,last_month_install_cnt)   AS last_month_install_cnt
,IF(dayofmonth('$date')='1',install_cnt,this_month_install_cnt+install_cnt)  AS this_month_install_cnt
FROM 
(
SELECt 
   app_id   
   ,sum_install_cnt  
   ,last_month_install_cnt  
   ,this_month_install_cnt  
FROM dws_store_install_ds  
WHERe  pt_d='$last_date'
) t1
FULL OUT JOIN 
(
SELECt 
    app_id    
   ,install_cnt    
FROM dws_store_install_dm
WHERe pt_d='$date'
) t2
ON t1.app_id = t2.app_id
;
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/689854.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号