Save up to $499! Grab all Python courses for $49 or all online courses we’ve ever launched for only $169. Only Feb 11-16. Happy Valentine's!
Introduction
The very basics
Infinite looping
Processing graphs with recursive CTE
27. Traveling salesman 2
Summary

Instruction

Excellent. Let's take the next step in the construction of our query.

Exercise

We've turned your previous query into a CTE. Your task is to complete the outer query based on the template. For London and all roads from London, show the following columns:

  • path - for London, it's simply 'London', for other cities, it will be the path from London in the following format: London->CityName,
  • lat,
  • lon,
  • total_distance - here: distance from London to that city,
  • count_places - here: 2.

You can use the function lat_lon_distance(lat1,lon1,lat2,lon2) that we prepared for you to calculate the distance between two cities.

Stuck? Here's a hint!

In the outer query, first select all information for London from the CTE, then use UNION ALL and construct the path using the concatenation operator ||.