0

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.

Damini Suthar
  • 1,470
  • 2
  • 14
  • 43
Ilyass
  • 35
  • 6
  • Does this help ? https://stackoverflow.com/questions/1736010/how-to-group-by-week-in-mysql – VBoka Apr 20 '22 at 06:40
  • *i'm trying to group the result by weeks* What is "week" in your case? calendar weeks? or 7-day periods starting from some base data? Does the week divided by new year should be treated as solid week or as two partial weeks? See [WEEK() function](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week) – Akina Apr 20 '22 at 06:52
  • 1
    Thank you so much for helping you answered what I'm looking for. – Ilyass Apr 20 '22 at 07:20

1 Answers1

1
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);
Damini Suthar
  • 1,470
  • 2
  • 14
  • 43