我有一张结构表:
id|name| date
---------------------------
1|qwer|2011-08-29 13:11:59
2|wert|2011-08-29 13:11:59
3|erty|2011-08-30 13:11:59
4|rtyu|2011-08-31 13:11:59
我需要一个查询来显示这样的数据:
day |number_of_entries
----------------------------
2011-08-29| 2
2011-08-30| 1
2011-08-31| 1
答案 0 :(得分:3)
使用GROUP BY
函数和COUNT
函数提供以下内容:
SELECT DATE(`date`), COUNT(*) AS number_of_entires
FROM tablename
GROUP BY DATE(`date`)
ORDER BY `date`
答案 1 :(得分:1)
SELECT DATE(`date`) AS day,
COUNT(*) AS number_of_entries
FROM mytable
GROUP BY DATE(`date`)
使用MySQL的DATE()
功能。