您的当前位置:首页正文

SQL生成整年日期表(全)

2024-11-07 来源:个人技术集锦

背景:折线图生成全年时间数据

Oracle版本: 

insert into year_oracle 
select to_date('20220101','yyyymmdd')+rownum-1 
from all_objects 
where rownum <= to_char(to_date('20221231','yyyymmdd'),'ddd');

 Hive版本:

select 
date_add(date_format('2022-01-01','yyyy-MM-dd'),rownum) 
from
(
select 
cast(row_number() OVER (ORDER BY 1) as int)-1 AS rownum
from dim_hive.product
)tt
where rownum <= 364;

 

Top