i want to group my data by yearweek but the week starts here in sunday.
how can i group my week from monday till sunday?
Here is my query:
SELECT YEARWEEK(dateStats) k,dateStats udate, COUNT(f_shop) sales
FROM sal_import WHERE dateStats BETWEEN "2011-08-15" AND "2011-08-21" GROUP BY YEARWEEK(dateStats)
The Between has a date from Monday till Sunday and i need just one row at the result.
Thank you very much
解决方案
Second argument of YEARWEEK(date[,mode]) function is mode - like in WEEK(date[,mode]) function.
You can specify start day - default is 0 (Sunday).
Just set it to 1 (Monday):
YEARWEEK(dateStats, 1)
本文介绍如何在SQL查询中调整日期分组方式,确保周分组从周一至周日,而非默认的周日至周六。通过修改YEARWEEK函数的第二个参数,可以轻松实现这一需求。
1884

被折叠的 条评论
为什么被折叠?



