Total records per day in the last 30 days [duplicate]

0

Galera,

I just did this query, it works great until today (day 20) minus 19, only I need it to show the last 30 days.

This works

SELECT ID, DAY( created_at ) AS DIA, SUM( 1 ) AS HORAS
FROM registration
WHERE created_at
BETWEEN CURRENT_DATE( ) -19
AND CURRENT_DATE( ) 
GROUP BY DAY( created_at ) 
ORDER BY DAY( created_at )

This returns the wrong amount

SELECT ID, DAY( created_at ) AS DIA, SUM( 1 ) AS HORAS
FROM registration
WHERE created_at
BETWEEN CURRENT_DATE( ) -30
AND CURRENT_DATE( ) 
GROUP BY DAY( created_at ) 
ORDER BY DAY( created_at ) 
    
asked by anonymous 20.06.2017 / 19:18

1 answer

2

Oops, check if this SQL works:

SELECT ID, DAY( created_at ) AS DIA, SUM( 1 ) AS HORAS
FROM registration
WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY DAY( created_at ) 
ORDER BY DAY( created_at )
    
20.06.2017 / 19:23