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 around four cites in France, and he needs to do it as quickly as possible. His friends from the development team decided to help him. We've created two new tables: city (with the id and name of each city) and road (with city_from, city_to and the time required to travel).

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

In your answer, provide the following columns:

  • path – city names separated by '->',
  • last_id – ID of the last city,
  • total_time – total time spent driving,
  • count_places – the number of places visited, should equal 4.