Round date to 10 minutes interval

后端 未结 7 2092
独厮守ぢ
独厮守ぢ 2021-02-19 07:26

I have a DATE column that I want to round to the next-lower 10 minute interval in a query (see example below).

I managed to do it by truncating the seconds

7条回答
  •  故里飘歌
    2021-02-19 08:15

    I think to solve this there's a much easier and faster way to round to a next lower 10 seconds, 1 Minute, 10 Minute etc. interval. Try to manipulate your timestamp as a string using SUBSTR() like this:

    SELECT 
    SUBSTR(datetime(d),1,18)||'0' AS Slot10sec, 
    SUBSTR(datetime(d),1,17)||'00' AS Slot1min, 
    SUBSTR(datetime(d),1,15)||'0:00' AS Slot10min, 
    SUBSTR(datetime(d),1,14)||'00:00' AS Slot1h, 
    MY_VALUE
    FROM MY_TABLE;
    

提交回复
热议问题