Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- top 1
- CONCAT(f0.from_city, COALESCE('-' + f0.to_city, ''), COALESCE('-' + f1.to_city, ''), COALESCE('-' + f2.to_city, ''),
- COALESCE('-' + f3.to_city, '')) AS route
- ,
- (f0.duration + ISNULL(f1.duration, 0) + ISNULL(f2.duration, 0) + ISNULL(f3.duration, 0)) AS total_duration
- FROM
- flights f0
- LEFT JOIN flights f1
- ON f1.from_city = f0.to_city AND f1.to_city NOT IN (f0.from_city)
- LEFT JOIN flights f2
- ON f2.from_city = f1.to_city AND f2.to_city NOT IN (f0.from_city, f1.from_city)
- LEFT JOIN flights f3
- ON f3.from_city = f2.to_city AND f3.to_city NOT IN (f0.from_city, f1.from_city, f2.from_city)
- WHERE
- f0.from_city = 'Kharkiv'
- AND 'Vancouver' IN (f0.to_city, f1.to_city, f2.to_city, f3.to_city)
- ORDER BY total_duration, route
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement