有桌子
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)
也失败了
答案 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