Skip to content
Advertisement

Group timestamp by hour SQLite

I am trying to group my timestamp column which has a data type of TimeStamp by hour.

So this works for grouping by day:

I have tried the following for grouping by hour:

But this gives me the error: no such function: HOUR:

I have seen similar questions asked, but it was DateTime used, not TimeStamp.

Additionally I would like to know how to group by any time period e.g by 24 hr, by 48 hr, by week, etc..

Advertisement

Answer

There is a method strftime in SQLite, Generally group by will work with an Aggregate function like (count, sum, avg …).

TestDLL

Here is a sample for strftime method.

Query

sqlfiddle

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement