Files
MarketAnalysis-ETL/EXTERNAL/CHPA/02 dws_ims_td_date.sql
2026-04-20 14:55:25 +08:00

28 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Databricks notebook source
-- 依赖事实表 tmp.tmp_ims_tf_fact_sales 所以一定要放后面。
--基于Fact数据动态计算时间维度 最近五年
insert overwrite table dws.dws_ims_td_date
select distinct
YM,
left(cast(YM as string),4) as YEAR,
right(cast(YM as string),2) as MONTH,
concat(
'Q',quarter(
date(
concat(
left(cast(YM as string),4),'-',right(cast(YM as string),2),'-01'
)))) as QUARTER,
concat(
left(cast(YM as string),4),'Q',quarter(
date(
concat(
left(cast(YM as string),4),'-',right(cast(YM as string),2),'-01'
)))) as YQ,
case when YM=(select max(YM) from tmp.tmp_ims_tf_fact_sales) then 'R' else right(cast(YM as string),2) end as DATE_FLAG,
case when YM%100>6 then concat(left(cast(YM as string),4),'H2') else concat(left(cast(YM as string),4),'H1') end as HALF_YEAR,
from_utc_timestamp(current_timestamp(),'UTC+8'),
from_utc_timestamp(current_timestamp(),'UTC+8')
from tmp.tmp_ims_tf_fact_sales
where YM > (select max(YM)-900 from tmp.tmp_ims_tf_fact_sales)
order by YM desc
;