Hive QL 依据日期维表将一年中的每个月补齐成指定天数(例如33天),补齐的日期用改月最后一日的日期

8 篇文章 0 订阅

日期维表结构如下
在这里插入图片描述

思路:

  1. 依据天数来进行补齐,小于33天的依次用最后日期拼上对应的天数
  2. 当天数为28天时,年-月-日 29天,
    年-月-日 30天,
    年-月-日 31天,
    年-月-日 32天,
    年-月-日 33天,
  3. 使用union all 将其它天数的处理结果上下拼接
  4. 排除日期为null的行
select
f.zdate,
f.num
from
(select
case when count(t1.zdate) = '28' then concat(t1.yearmonth,'-28') else null end as zdate,
'29' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '28' then concat(t1.yearmonth,'-28') else null end as zdate,
'30' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '28' then concat(t1.yearmonth,'-28') else null end as zdate,
'31' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '28' then concat(t1.yearmonth,'-28') else null end as zdate,
'32' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '28' then concat(t1.yearmonth,'-28') else null end as zdate,
'33' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '29' then concat(t1.yearmonth,'-29') else null end as zdate,
'30' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '29' then concat(t1.yearmonth,'-29') else null end as zdate,
'31' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '29' then concat(t1.yearmonth,'-29') else null end as zdate,
'32' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '29' then concat(t1.yearmonth,'-29') else null end as zdate,
'33' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '30' then concat(t1.yearmonth,'-30') else null end as zdate,
'31' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '30' then concat(t1.yearmonth,'-30') else null end as zdate,
'32' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '30' then concat(t1.yearmonth,'-30') else null end as zdate,
'33' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '31' then concat(t1.yearmonth,'-31') else null end as zdate,
'32' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
case when count(t1.zdate) = '31' then concat(t1.yearmonth,'-31') else null end as zdate,
'33' as num
from db_cfg_dev.cfg_period_d t1
group by
yearmonth
union all
select
t1.zdate,
substr(t1.zdate,9,2)
from db_cfg_dev.cfg_period_d t1) f
where f.zdate is not null;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值