Reputation: 4953
I'm getting the following data using two queries which I'm then using a UNION ALL
to combine:
IN
events are sorted using SideA then EventTimeOUT
events are sorted the same wayHowever, I'd like the final result to be as follows:
OUT
events in the corresponding EventTime where out.SideB=in.SideA
So the final result should be like this:
Please advise how to proceed.
PS: Please find the data used in my example in this GoogleSheet
Upvotes: 1
Views: 39
Reputation: 222432
I am thinking of an order by
clause like:
order by
-- if event type is 1, order by SideA, else order by SideB
case when EventType = 'IN' then SideA else SideB end,
-- then event time
EventTime,
-- `Out` goes before `IN` if there are several events at the same time
EventType desc
Upvotes: 3