Search code examples
sqlsybasesap-ase

Group by data by 5 mintues sample


I am having a table like this and I am storing epoch time as one column. I want to use epoch time column to group by data by 5 min

-------------------
Name | epoch_time |
A    | 1585977780 |
B    | 1585977780 |
C    | 1585978080 |
-------------------

Solution

  • You have Unix time, so you can use arithmetic:

    select floor(epoch_time / (60 * 5)) * 60 * 5 as minutes_5, count(*)
    from t
    group by floor(epoch_time / (60 * 5)) * 60 * 5