在下表中
+-------+-----------------------+
| id | timestamp |
+-------+-----------------------+
| 1 | 2010-06-10 14:35:30 |
| 2 | 2010-06-10 15:27:35 |
| 3 | 2010-06-10 16:39:36 |
| 4 | 2010-06-11 14:55:30 |
| 5 | 2010-06-11 18:45:31 |
| 6 | 2010-06-12 20:25:31 |
+-------+-----------------------+
我希望能够计算日期(时间被忽略)。所以输出应该如下:
+-------+-----------------------+
| id | type | count |
+-------+-----------------------+
| 1 | 2010-06-10 | 3 |
| 2 | 2010-06-11 | 2 |
| 3 | 2010-06-12 | 1 |
+-------+-----------------------+
对此有什么疑问?
答案 0 :(得分:5)
如果结果中没有id
列,则可以使用此功能:
SELECT DATE(timestamp) AS type, COUNT(*) AS `count`
FROM sometable
GROUP BY DATE(timestamp)
ORDER BY DATE(timestamp)
答案 1 :(得分:0)
SELECT
DATE(timestamp),
COUNT(*)
FROM
My_Table
GROUP BY
DATE(timestampe)
这不会为每行提供行号。我不知道(为什么?)这很重要。
答案 2 :(得分:0)
select date(timestamp) as type, count(*)
from your_table
group by type;
答案 3 :(得分:0)
这可能有用......
select DATE(timestamp), count(timestamp)
from _table
group by timestamp
order by count(timestamp) desc
答案 4 :(得分:0)
SELECT count(DATE_FORMAT(时间戳,'%Y-%m-%d /')),DATE_FORMAT(时间戳,'%Y-%m-%d') FROM tablename 按DATE_FORMAT分组(时间戳,'%Y-%m-%d');
您不能在选择中包含ID,否则计数将会关闭。