Oracle SQL - results from a subquery range -
i figure out across weekend, hard focus late on friday...
query 1 below returns trip, arrive , depart value @ given location.
query 2 below returns trip, arrive , depart value @ 2nd location.
these 2 queries straightforward.
i want return only results in query 2,when query 2 depart times between any of query 1's arrive , depart times.
in essence, give me instance of trip departing 'ber2' before trip @ 'ber3' has departed.
query 1
select rtdev.trip_headers.trip_name, rtdev.trip_bodies.arrival_time, rtdev.trip_bodies.departure_time rtdev.trip_headers inner join rtdev.trip_bodies on rtdev.trip_headers.tme_id = rtdev.trip_bodies.tme_id , rtdev.trip_headers.thr_id = rtdev.trip_bodies.thr_id inner join rtdev.tnoded on rtdev.tnoded.nid = rtdev.trip_bodies.current_node (rtdev.tnoded.strshortname = 'ber3') , (rtdev.trip_bodies.tme_id = 9860)
query 2
select trip_headers_1.trip_name, trip_bodies_1.arrival_time, trip_bodies_1.departure_time rtdev.trip_headers trip_headers_1 inner join rtdev.trip_bodies trip_bodies_1 on trip_headers_1.tme_id = trip_bodies_1.tme_id , trip_headers_1.thr_id = trip_bodies_1.thr_id inner join rtdev.tnoded tnoded_1 on tnoded_1.nid = trip_bodies_1.current_node (tnoded_1.strshortname = 'ber2') , (trip_bodies_1.tme_id = 9860)
any suggestions?
it's simple - can put query2
inside inline view (a view in from
clause) this:
select trip_headers_1.trip_name, trip_bodies_1.arrival_time, trip_bodies_1.departure_time rtdev.trip_headers trip_headers_1 inner join rtdev.trip_bodies trip_bodies_1 on trip_headers_1.tme_id = trip_bodies_1.tme_id , trip_headers_1.thr_id = trip_bodies_1.thr_id inner join rtdev.tnoded tnoded_1 on tnoded_1.nid = trip_bodies_1.current_node -- put query 2 here -- join (select rtdev.trip_headers.trip_name, rtdev.trip_bodies.arrival_time, rtdev.trip_bodies.departure_time rtdev.trip_headers inner join rtdev.trip_bodies on rtdev.trip_headers.tme_id = rtdev.trip_bodies.tme_id , rtdev.trip_headers.thr_id = rtdev.trip_bodies.thr_id inner join rtdev.tnoded on rtdev.tnoded.nid = rtdev.trip_bodies.current_node (rtdev.tnoded.strshortname = 'ber3') , (rtdev.trip_bodies.tme_id = 9860)) query2 -- , put join condition -- on trip_bodies_1.departure_time between query2.arrival_time , query2.departure_time (tnoded_1.strshortname = 'ber2') , (trip_bodies_1.tme_id = 9860)
Comments
Post a Comment