Home > database >  Group by weeks in a range of date
Group by weeks in a range of date

Time:04-20

I am using a MySQL database and I'm trying to group the result by weeks, I know how to group by DAY or MONTH or YEAR but not by week, this is my query:

SELECT DATE_FORMAT(Builds.date,"%y-%m-%d") as date, Labels.label_name
       
FROM Builds JOIN Labels ON Builds.Labels_label_id = Labels.label_id

GROUP BY MONTH(date)

Thank you for helping.

CodePudding user response:

SELECT YEAR(Builds.date), WEEKOFYEAR(Builds.date) , Labels.label_name 
FROM Builds JOIN Labels ON Builds.Labels_label_id = Labels.label_id 
GROUP BY YEAR(Builds.date), WEEKOFYEAR(Builds.date);
  • Related