Introduction
The very basics
Infinite looping
Processing trees with recursive CTEs
Processing graphs with recursive ctes
Summary
37. Exercise 3

Instruction

Very good! The last problem deals with graphs.

Exercise

We want to travel between the four cities presented in the Destination table, starting from Warsaw. We have another table called Ticket, which lists all possible flight connections for us.

Your task is to find the path which will be cheapest in terms of the total tickets' cost. List all paths starting from Warsaw that go through all four cities. Order the paths in descending order by TotalCost.

In your answer, provide the following columns:

  • Path – city names, separated by N'->',
  • LastId – the ID of the last city,
  • TotalCost – the total cost of tickets,
  • CountPlaces – the number of places visited; it should equal 4.