日常在数据处理过程中,经常会用到日期字典,下述代码将常用日期字典字段信息生成,纯sql版,方便
select
rn as id -- 唯一主键
,iso_date as iso_date -- 日期 yyyy-MM-dd格式
,dayofweek as dayofweek -- 当天在本周的序号 1-7
,dayofmonth as dayofmonth -- 当天在本月的序号 1-31
,dayofyear as dayofyear -- 当天在本年的序号 1-366
,weekofmonth as weekofmonth -- 本周在本月序号 1-4
,weekofyear as weekofyear -- 本周在本年序号 1-52
,iso_week_start as iso_week_start -- 本周周一 yyyy-MM-dd格式
,iso_week_end as iso_week_end -- 本周周末 yyyy-MM-dd格式
,monthofyear as monthofyear -- 本月在本年的序号 1-12
,iso_month_start as iso_month_start -- 本月第一天 yyyy-MM-dd格式
,iso_month_end as iso_month_end -- 本月最后一在 yyyy-MM-dd格式
,quarterofyear as quarterofyear -- 季度在本年序号 1-4
,concat(year,'-01-01')