简体   繁体   中英

Count how many table entries have been made per day via MySQL

I have a table for every event on my website called event_archive. I can count how many events have been registered with this query:

SELECT COUNT(*) FROM event_archive
WHERE event_time BETWEEN '2017-01-01 00:00:00' AND '2017-08-31 23:59:59';

Is there any way to show how many entries have been made per day?

You can use group by for get a count for day

SELECT date(event_time) , COUNT(*) 
FROM event_archive
WHERE event_time BETWEEN '2017-01-01 00:00:00' AND '2017-08-31 23:59:59'
group by  date(event_time)

and you can build the date using date() function

Yes by using the GROUP BY and the DATE() function

SELECT DATE(event_date) as theDate, COUNT(*) 
FROM event_archive
WHERE event_time BETWEEN '2017-01-01 00:00:00' AND '2017-08-31 23:59:59'
GROUP BY DATE(event_time)';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM