简体   繁体   中英

hsqldb count for each day

having table

id|date|somefield

I need to get count of entries for each day of the year

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

works fine

but when I try

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

fails

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

fails as well

You need to add a group by expression. Here is some pseudo code, I will work up a SqlFiddle in a moment.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM