I have the following data:
Client_id Call_started Call_ended Outcome_id
----------- -------------------------- -------------------------- ----------------
111 Aug. 21, 2018, 4:10 p.m. Aug. 21, 2018, 4:13 p.m. Rescheduled
111 Aug. 22, 2018, 1:00 p.m. Aug. 22, 2018, 1:10 p.m. Rescheduled
112 Aug. 21, 2018, 3:10 p.m. Aug. 21, 2018, 3:11 p.m. Rescheduled
111 Aug. 22, 2018, 5:00 p.m. Aug. 22, 2018, 5:08 p.m. Interested
113 Aug. 22, 2018, 1:00 p.m. Aug. 22, 2018, 1:10 p.m. Rescheduled
114 Aug. 21, 2018, 2:10 p.m. Aug. 21, 2018, 2:11 p.m. NotReachable
112 Aug. 22, 2018, 9:10 a.m. Aug. 22, 2018, 9:20 a.m. NotInterested
113 Aug. 22, 2018, 5:20 p.m. Aug. 22, 2018, 5:25 p.m. Interested
Below is the SQL query for client calls which got rescheduled
Select a.client_id, a.call_start,a.call_end, a.outcome_id
From client_analysis a
where a.outcome_id like %Rescheduled%'
Now I also want to select what happened to follow-up rescheduled calls (were they called on time, etc). How can I select other calls made (or next a.call_start) to the given client_ids where a.outcome_id is rescheduled (next a.call_start < rescheduled a.call_end)?
Below is the expected output:
Client_id Call_started Call_ended Outcome_id
----------- -------------------------- -------------------------- ----------------
111 Aug. 21, 2018, 4:10 p.m. Aug. 21, 2018, 4:13 p.m. Rescheduled
111 Aug. 22, 2018, 1:00 p.m. Aug. 22, 2018, 1:10 p.m. Rescheduled
111 Aug. 22, 2018, 5:00 p.m. Aug. 22, 2018, 5:08 p.m. Interested
112 Aug. 21, 2018, 3:10 p.m. Aug. 21, 2018, 3:11 p.m. Rescheduled
112 Aug. 22, 2018, 9:10 a.m. Aug. 22, 2018, 9:20 a.m. NotInterested
113 Aug. 22, 2018, 1:00 p.m. Aug. 22, 2018, 1:10 p.m. Rescheduled
113 Aug. 22, 2018, 5:20 p.m. Aug. 22, 2018, 5:25 p.m. Interested
Call_start are in the same columns for a given client_id and based on start time we can figure out the sequence of the calls made.