How to group records by interval 4 hours? For example, I have rows that contain data about events durations. event_id start_date end_date 1 2024-08-16 14:30:00 2024-08-16 16:00:00 1 2024-08-16 16:00:00 2024-08-16 17:30:00 1 2024-08-16 17:30:00 2024-08-16 19:00:00 1 2024-08-16 19:00:00 2024-08-16 20:30:00 1 2024-08-16 20:30:00 2024-08-16 22:00:00 1 2024-08-16 22:00:00 2024-08-16 23:30:00 I want to group them but max duration of 1 row should be 4 hours. Result: event_id start_date end_date 1 2024-08-16 14:30:00 2024-08-16 17:30:00 1 2024-08-16 17:30:00 2024-08-16 20:30:00 1 2024-08-16 20:30:00 2024-08-16 23:30:00 I tried to use something like this to display an increased duration but no idea how to use it for grouping select sum(end_date - start_date) over (partition by event_id order by start_date) Continue reading...