Group records by time Group records by time sqlite sqlite

Group records by time


Give this a try:

select datetime((strftime('%s', time) / 900) * 900, 'unixepoch') interval,       count(*) cntfrom tgroup by intervalorder by interval

Check the fiddle here.


I have limited SQLite background (and no practice instance), but I'd try grabbing the minutes using

strftime( FORMAT, TIMESTRING, MOD, MOD, ...)

with the %M modifier (http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html)

Then divide that by 15 and get the FLOOR of your quotient to figure out which quarter-hour you're in (e.g., 0, 1, 2, or 3)

cast(x as int)

Getting the floor value of a number in SQLite?

Strung together it might look something like:

Select cast( (strftime( 'YYYY-MM-DD HH:MI:SS', your_time_field, '%M') / 15) as int) from your_table

(you might need to cast before you divide by 15 as well, since strftime probably returns a string)

Then group by the quarter-hour.

Sorry I don't have exact syntax for you, but that approach should enable you to get the functional groupings, after which you can massage the output to make it look how you want.