Building on this question:
How would the accepted answer change if the events
table contained a "Room" column with multiple values and you wanted to take out the overlapping meetings by room? The table could look like:
id start end created_at room
1 2019-01-23 18:30:00.0 2019-01-23 19:00:00.0 2019-01-18 21:28:27.427612 Room1
2 2019-01-23 18:30:00.0 2019-01-23 19:00:00.0 2019-01-23 01:04:05.861876 Room1
3 2019-01-23 18:00:00.0 2019-01-23 18:45:00.0 2019-01-16 17:14:50.709552 Room1
4 2019-01-23 18:30:00.0 2019-01-23 19:30:00.0 2019-01-22 19:24:05.532491 Room1
5 2019-01-23 18:30:00.0 2019-01-23 19:30:00.0 2019-01-18 17:28:40.074205 Room1
6 2019-01-23 20:00:00.0 2019-01-23 20:30:00.0 2019-01-18 15:22:30.736888 Room1
7 2019-01-23 20:15:00.0 2019-01-23 20:45:00.0 2019-01-20 20:20:20.202020 Room1
8 2019-01-23 18:30:00.0 2019-01-23 19:00:00.0 2019-01-18 21:28:27.427612 Room2
9 2019-01-23 18:30:00.0 2019-01-23 19:00:00.0 2019-01-23 01:04:05.861877 Room2
10 2019-01-23 18:00:00.0 2019-01-23 18:45:00.0 2019-01-16 17:14:50.709552 Room2
11 2019-01-23 18:30:00.0 2019-01-23 19:30:00.0 2019-01-22 19:24:05.532491 Room2
12 2019-01-23 18:30:00.0 2019-01-23 19:30:00.0 2019-01-18 17:28:40.074205 Room2
13 2019-01-23 20:00:00.0 2019-01-23 20:30:00.0 2019-01-18 15:22:30.736888 Room2
14 2019-01-23 20:15:00.0 2019-01-23 20:45:00.0 2019-01-20 20:20:20.202020 Room2
15 2019-01-23 20:00:00.0 2019-01-23 20:30:00.0 2019-01-18 15:22:30.736888 Room3
16 2019-01-23 20:15:00.0 2019-01-23 20:45:00.0 2019-01-20 20:20:20.202021 Room3
With the end result being:
id start end created_at room
2 2019-01-23 18:30:00.0 2019-01-23 19:00:00.0 2019-01-23 01:04:05.861876 Room1
7 2019-01-23 20:15:00.0 2019-01-23 20:45:00.0 2019-01-20 20:20:20.202020 Room1
9 2019-01-23 18:30:00.0 2019-01-23 19:00:00.0 2019-01-23 01:04:05.861877 Room2
14 2019-01-23 20:15:00.0 2019-01-23 20:45:00.0 2019-01-20 20:20:20.202020 Room2
16 2019-01-23 20:15:00.0 2019-01-23 20:45:00.0 2019-01-20 20:20:20.202021 Room3
The answer from the previous question below can only give the latest created event in the time block across ALL rooms, not by room.
select max(id), min(start), max(end), max(created_at)
from (select t.*,
count(*) filter (where max_end < end) over (order by start) as grouping
from (select t.*,
max(end) over (order by start rows between unbounded preceding and 1 preceding) as max_end
from events t
) t
) t
group by grouping;