Mysql week from monday to sunday

I want to group my data by year, but the week starts here on Sunday. How can I group my week from Monday to Sunday?

Here is my request:

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)

There is a date between Monday and Sunday, and I only need one line as a result.

Many thanks

+5
source share
3 answers

The second argument to the function YEARWEEK(date[,mode])is mode- as in WEEK(date[,mode]).

You can specify the starting day - this is the default 0 (Sunday).

Just set it to 1 (Monday):

YEARWEEK(dateStats, 1)
+18
source

You can set a global variable for this purpose:

Additional Information

If you are lazy

  --default_week_format=1
0
source

. , "Weekday", "Weekend", "Week number", "Financial Quarter" ..

. :

, 0

YEARWEEK, ..

, !

0

All Articles