1

有桌子

id|date|somefield

我需要计算一年中每一天的条目数

select EXTRACT (DAY_OF_YEAR FROM date) as day, id from table

工作正常

但是当我尝试

select EXTRACT (DAY_OF_YEAR FROM date) as day, count(*) from table

失败

select count(*) from table group by EXTRACT (DAY_OF_YEAR FROM date)

也失败了

4

1 回答 1

1

您需要添加一个group by表达式。这是一些伪代码,稍后我将编写一个 SqlFiddle。

select EXTRACT (DAY_OF_YEAR FROM date) as day, 
count(*) 
from table
group by EXTRACT (DAY_OF_YEAR FROM date)

SQLFIDDLE(使用 MYSQL) http://sqlfiddle.com/#!2/42c9e/10

于 2013-06-02T09:34:04.670 回答