I have the following table_1 which shows the time each person in Room_A.
person | start_time | end_time |
---|---|---|
John | 5 | 16 |
Mary | 7 | 10 |
Peter | 8 | 12 |
Then I want to have an output table which shows the time and the people in the Room_A, like:
people | start_time | end_time |
---|---|---|
[John] | 5 | 7 |
[John, Mary] | 7 | 8 |
[John, Mary, Peter] | 8 | 10 |
[John, Peter] | 10 | 12 |
[John] | 12 | 16 |
I am wondering if this is something achievable using SQL/Presto query ? Thanks!
2
Answers
I suggest the following (untested) query:
I have the equivalent query operating (in Postgres) here: https://dbfiddle.uk/n6b28oZb and the query above is (I believe) suitable for Presto
But I have just noticed it isn’t a full match to your wanted result
the idea being to JOIN with the generated list of all possible intervals: