记录一下 sql
编写生成从一个确定的起始月份到当前月份的连续月份序列
SELECT
substr(add_months(table1.start_dt,table2.pos),1,4) AS INDICT_YEAR,
substr(add_months(table1.start_dt,table2.pos),1,7) AS INDICT_MON
FROM
(
SELECT '2024-01-01' AS start_dt
,substr(CURRENT_DATE(),1,10) AS end_dt
) table1 lateral view posexplode(split(repeat(',', (YEAR(end_dt) - YEAR(start_dt)) * 12 + (MONTH(end_dt) - MONTH(start_dt))), ',')) table2 AS pos, val
运行结果: