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.
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.
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)