Group records by time

后端 未结 2 880
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 07:44

I have a table containing a datetime column and some misc other columns. The datetime column represents an event happening. It can either contains a time (event happened at

2条回答
  •  醉梦人生
    2020-12-18 08:32

    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.

提交回复
热议问题