I have the below table and I would like to find out which customers made a trip where his/her start_location is the end_location of another customer who made the trip <= 5 minutes before him/her.
For instance, this is what I have:
DT Customer_Name Start_location End_location Trip_fare
2019-11-01 08:17:42 Jane A B $10
2019-11-01 08:18:02 Mary C A $7
2019-11-01 08:18:04 Tom B D $12
2019-11-01 08:20:11 Harry E C $20
2019-11-01 08:21:22 Alex D A $5
2019-11-01 08:24:30 Sally C B $8
This is what I want:
DT Customer_Name Start_location End_location
2019-11-01 08:17:42 Jane A B
2019-11-01 08:18:04 Tom B D (cause Tom's start_location = B = Jane's end_location and the time difference between the 2 trips is within 5 minutes)
2019-11-01 08:21:22 Alex D A
2019-11-01 08:20:11 Harry E C
2019-11-01 08:24:30 Sally C B
Here, Mary has been removed from the list as her start_location = 'C', which is not the end_location of Jane who made a trip <= 5 minutes before her.
My apologies for this 'messy' looking question. Do let me know if you need further clarifications!
Thank you so much for your help!