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
MySQL WEEK() Function The WEEK() function returns the week number for a given date (a number from 0 to 53).
MySQL WEEKDAY() Function The WEEKDAY() function returns the weekday number for a given date. Note: 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.
MySQL interval is an operator, which is based on the binary search algorithm to search the items and returns the value from 0 to N. It is mainly used to calculate the date and time values. We can use the following syntax to create an interval value: INTERVAL expr unit.
MySQL DAY() function MySQL DAY() returns the day of the month for a specified date. The day returned will be within the range of 1 to 31. If the given date is '0000-00-00', the function will return 0. The DAYOFMONTH() is the synonym of DAY().
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With