hsqldb计算每一天

时间:2013-06-02 09:27:45

标签: sql hsqldb

有桌子

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)

也失败了

1 个答案:

答案 0 :(得分: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