Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
11. Complex recursive CTE – graphs


Amazing! The last recursion question is about graphs.


One of the project managers needs to travel to four cities in France, and he needs to do it as quickly as possible. His friends from the development team have decided to help him. We've created two new tables: City (with the Id and Name of each city) and Road (with CityFrom, CityTo, and the time required to travel).

The manager starts in Paris. Your task is to find the shortest path in terms of the total travel time.

In your answer, provide the following columns:

  • Path – the city names separated by N'->',
  • LastId – the ID of the last city,
  • TotalTime – the total time spent driving,
  • CountPlaces – the number of places visited, this should equal 4.