简体   繁体   中英

How to do query with timestamp?

I have this table:

id (int)
name (varchar)
insert (timestamp)

An example row is this:

14, John, 2010-02-25 01:48:36

In this table I have 1 million of rows and I want to know how many rows have been inserted in each day. So I want something like this:

2010-02-25 153
2010-02-24 98
2010-02-23 219
2010-02-22 127
...

What query do I have to do ?

Try this:

SELECT DATE(`insert`) AS day, COUNT(*) AS cnt
FROM your_table
GROUP BY day

Note that days that have no rows will not be represented in the result set.

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