MySQL grouped by week based on date column?

I have a table with a date column, and I would like to try to group it using the week as a time reference to calculate how many rows happened per week. I did this for several days using GROUP BY Date ( Date_Column ), but I'm not sure how to do it in a week?

thanks

+4
source share
3 answers
 SELECT ... FROM .... GROUP BY YEAR(Date_column), WEEKOFYEAR(Date_Column); 
+5
source
 SELECT week(Date_Column) FROM .... GROUP BY week(Date_Column); 
+2
source

Try putting GROUP BY YEARWEEK(date_column) at the end of your query - this will also take into account the year in which the date is.

+2
source

All Articles