The problem was created by me, discussed with my co-workers and no one seem to have an idea. Thus, thought, I can ask the experts here.
I’ve the following table
FlightInfo and the fields are
Start
Destination
Flight_Duration
The goal is to find out, the shortest flight between two cities. The challenge is not all cities have direct flights. (Example: PHL to PVA ->Philadelphia to Shangai). You have to connect in Detroit (DTW) or Chicago (ORD)
How will you go about writing an SQL statement?
Example table contents
PHL DTW 2.25
DTW PVG 15.15
PHL ORD 3.15
ORD PVG 16.20
Brute force:
Answer:
Edit note: I have modified the implementation of the CTE with one which is resilient to cycles and is also actually correct.