How to group data per week in mysql [closed]

1

I am extracting some data and want to know some way to group the data by week. I am giving SELECT and it is bringing the data from last month and I am already grouping by day, but I need it to be per week.

    
asked by anonymous 17.10.2018 / 15:24

1 answer

1

I decided to give GROUP BY YEARWEEK(DATA,1) - this 1 is the first day of the week.

SELECT DISTINCT DATE_FORMAT(created_at, '%Y-%m-%d') AS 'Primeiro dia da semana', COUNT(id) AS 'Total'
FROM payments 
WHERE status = 2 AND (created_at BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 month) AND CURDATE())
GROUP BY YEARWEEK(created_at, 1)
    
17.10.2018 / 15:44