有个问题,那你们是怎么定义跨月的。上个月一些周末到下个月,周日在下个月,要怎么算?
case
when (create_date) is NULL then ''
when cast(day(create_date) as float)/7=1 and cast(day(create_date) as int)%7=0 then CAST(MONTH(create_date) as VARCHAR(10))+ '月第1周'
when cast(day(create_date) as float)/7=2 and cast(day(create_date) as int)%7=0 then CAST(MONTH(create_date) as VARCHAR(10))+'月第2周'
when cast(day(create_date) as float)/7=3 and cast(day(create_date) as int)%7=0 then CAST(MONTH(create_date) as VARCHAR(10))+'月第3周'
when cast(day(create_date) as float)/7=4 and cast(day(create_date) as int)%7=0 then CAST(MONTH(create_date) as VARCHAR(10))+'月第4周'
when cast(day(create_date) as float)/7<1 then CAST(MONTH(create_date) as VARCHAR(10))+'月第1周'
when cast(day(create_date) as float)/7>1 and cast(day(create_date) as float)/7<2 then CAST(MONTH(create_date) as VARCHAR(10))+'月第2周'
when cast(day(create_date) as float)/7>2 and cast(day(create_date) as float)/7<3 then CAST(MONTH(create_date) as VARCHAR(10))+'月第3周'
when cast(day(create_date) as float)/7>3 and cast(day(create_date) as float)/7<4 then CAST(MONTH(create_date) as VARCHAR(10))+'月第4周'
else CAST(MONTH(create_date) as VARCHAR(10))+'月第5周'
end as week
这个是从1号开始,一周7天的算法。sql server,具体的看着修改。