Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Infinite looping
Processing trees with recursive CTEs
Processing graphs with recursive ctes
29. Traveling salesman 2
Summary

Instruction

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

Exercise

We've turned the 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 N'London', this is simply 'London'; for other cities, it will be the path from London in the following format: London->CityName
  • Lat,
  • Lon,
  • TotalDistance – here, distance from London to that city,
  • CountPlaces – here, 2.

You can use the following function, that we've prepared for you to calculate the distance between two cities:

dbo.LatLonDistance(lat1, lon1, lat2, lon2)

Don't show the path from London to London (London->London).

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 +.