London Smith London Smith - 1 year ago 66
MySQL Question

SQL count for each day

Is it possible to get in one shot a count(*) for each day of the last 15 days like I get for one day:

SELECT count(*) as total from users where `user_date_accountcreated` BETWEEN '2016-10-03 00:00:00' AND '2016-10-03 23:59:59'

To avoid making one SQL request per day.


Answer Source

Just use mysql's date functions:

WHERE u_d_a_c BETWEEN (now() - INTERVAL 15 DAY) AND now()
GROUP BY year(u_d_a_c), month(u_d_a_c), day(u_d_a_c)