Question
You are working for an airline company and you have received a dataset of Pilot’s travel time between cities. You need to determine the reciprocal and find the total travel hours between cities. That means, the pilot’s travel from city ‘1’ to ‘2’ and city ‘2’ to ‘1’ should be considered as one and then the total travel hours has to be calculated. Write an SQL query to achieve the expected output.
Answer
Let us create the test data first.city_1
and the other as city_2. To do this, you can use less than < or greater than > operator on from_city
and to_city
.

travel_time_hours
by grouping city_1
and city_2
.