I have table like this:
ID | Type | Time |
---|---|---|
Q001 | In | 2022-8-30 08:30:00 |
Q001 | Out | 2022-8-30 10:35:00 |
Q001 | In | 2022-8-30 10:42:00 |
Q001 | Out | 2022-8-30 12:15:00 |
I want to get result like this:
ID | In | out |
---|---|---|
Q001 | 2022-8-30 08:30:00 | 2022-8-30 10:35:00 |
Q001 | 2022-8-30 10:42:00 | 2022-8-30 12:15:00 |
I think maybe I can use two sub-tables for in and out data ordered by id and time,then create a table with same index of each table,like below
select Intable.id,
Intable.time,
Outtable.time
from (select * from T1
where type='IN' order by ID, Time as Intable)
join ( select * from T1
where type='out' as Outtable order by ID, Time)
where Intable.ID = Outtable.id
Is this possible? And how do I get from each table with same index? Thx.