SQL 当天在当月、当季度、当年的时间进度
首先需要一张日历表:KKKK.AAAAAA
(可人工维护,只需要一列date,月、季度、年都可以算出来)
字段:
date(每天的日期)
month(当天所处的月)
date_season(当天所处的季度)
year(当天所处的年)
select
date
,year(date) as date_year
,case when month(date)<=3 then 1
when month(date)<=6 then 2
when month(date)<=9 then 3
else 4 end as date_season
,month(date) as date_month
,weekofyear(date)