You can use the PIVOT function to get the result, I would just apply the row_number() window function for the data so that you can return multiple rows for each ID2 :
select id2, start, stop from ( select id2, status, time, row_number() over(partition by status order by time) seq from yourtable ) d pivot ( max(time) for status in (start, stop) ) piv order by start desc;
See SQL Fiddle with Demo .
You can also use the aggregate function with a CASE expression to get the final result:
select id2, max(case when status = 'start' then time end) start, max(case when status = 'start' then time end) stop from ( select id2, status, time, row_number() over(partition by status order by time) seq from yourtable ) d group by id2, seq;
See SQL script for a demo
Taryn
source share