SELECT
DATE,
DAYOFWEEK(DATE) w,
row_number()over( partition by date_format(date,"%Y") order by date asc ) s,
concat("第",TRUNCATE((row_number()over( partition by date_format(date,"%Y") order by date asc )-1)/7,0)+1,"周") as t
FROM
DIC_DATE
WHERE
DATE >= "2021-01-01"
AND DATE <= '2021-12-31'
-- LIMIT 111
以MySQL语法为例:
首先你需要有一个全年的【日期维度表】,然后按照我这个方法实现即可;
——————
纠正 :20210101-20210105为第一周 ===》20210101-20210107为第一周
——————