How to group datetime with 5 minutes interval.
This is my table
id Belongs_to dt
----------------------------------------
102 2020-08-07 2020-08-07 09:48:01.000
102 2020-08-07 2020-08-07 09:48:03.000
102 2020-08-07 2020-08-07 16:24:01.000
102 2020-08-07 2020-08-07 17:22:03.000
102 2020-08-07 2020-08-07 17:23:01.000
102 2020-08-07 2020-08-07 17:23:01.000
102 2020-08-07 2020-08-07 21:28:03.000
102 2020-08-07 2020-08-07 21:28:04.000
And I tried below query to group
select
t.emp_Reader_id, Belongs_to,
format(dt, 'yyyy-MM-dd HH:mm') as dt,
row_number() over (partition by t.emp_reader_id, Belongs_to order by FORMAT(dt, 'yyyy-MM-dd HH:mm')) as seqnum
from
trnevents t
where
T.emp_reader_id = 102
group by
t.emp_reader_id, format(dt, 'yyyy-MM-dd HH:mm'), Belongs_to
Now time seconds is neglected fine and also I want to group by 5 minutes interval if its in same time
Expected Output:
id Belongs_to dt seqnum
102 2020-08-07 2020-08-07 09:48 1
102 2020-08-07 2020-08-07 16:24 2
102 2020-08-07 2020-08-07 17:22 3
102 2020-08-07 2020-08-07 21:28 4