Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Total Ride Time for Each Subway Line Challenge | Grouping
course content

Course Content

Intermediate SQL

Total Ride Time for Each Subway Line ChallengeTotal Ride Time for Each Subway Line Challenge

The construction company has decided to increase the number of stations on the Yellow metro line.

Our next task is to find the turnaround time for each line. It's important for the company to ensure that they can close the Yellow line for maintenance and expansion by adding new metro stations, so it's crucial for them not to inconvenience passengers too much.

Therefore, we need to find the total turnaround time for the train by summing the time to each station (using the SUM() function).

Note:

If we simply calculate the sum of the time to each station, it will be the train's time from one end station to the other. However, it's also important for us to know the total turnaround time for the train along the metro line. To achieve this, we need to multiply the sum by 2.

To understand how to do this task, let's consider an example with an employees table.

Suppose we need to find the department with the highest average monthly salary.

For this, we can use the following query:

Thus, we obtain the necessary data as a result.

Let's return to the task because the workers await our verdict on the expansion of the metro station.

Here is the preview of a metro_travel_time table we are working with:

id line_name station_name time_to_next_station
1 Green Angrignon 10
2 Green Monk 16
3 Green Verdun 9
4 Green Charlevoix 17
... ... ... ...
21 Yellow Longueuil 10

Task

Calculate the turnaround time for each of the metro lines. To do this, use SUM(), group the data, and order in ascending order. The company already trusts you, as you have helped them a lot before.

Note:

Name the new column turnaround_time so that your solution can be successfully tested. Also, don't forget to multiply the sum of time by 2.

Everything was clear?

Section 1. Chapter 3
toggle bottom row
course content

Course Content

Intermediate SQL

Total Ride Time for Each Subway Line ChallengeTotal Ride Time for Each Subway Line Challenge

The construction company has decided to increase the number of stations on the Yellow metro line.

Our next task is to find the turnaround time for each line. It's important for the company to ensure that they can close the Yellow line for maintenance and expansion by adding new metro stations, so it's crucial for them not to inconvenience passengers too much.

Therefore, we need to find the total turnaround time for the train by summing the time to each station (using the SUM() function).

Note:

If we simply calculate the sum of the time to each station, it will be the train's time from one end station to the other. However, it's also important for us to know the total turnaround time for the train along the metro line. To achieve this, we need to multiply the sum by 2.

To understand how to do this task, let's consider an example with an employees table.

Suppose we need to find the department with the highest average monthly salary.

For this, we can use the following query:

Thus, we obtain the necessary data as a result.

Let's return to the task because the workers await our verdict on the expansion of the metro station.

Here is the preview of a metro_travel_time table we are working with:

id line_name station_name time_to_next_station
1 Green Angrignon 10
2 Green Monk 16
3 Green Verdun 9
4 Green Charlevoix 17
... ... ... ...
21 Yellow Longueuil 10

Task

Calculate the turnaround time for each of the metro lines. To do this, use SUM(), group the data, and order in ascending order. The company already trusts you, as you have helped them a lot before.

Note:

Name the new column turnaround_time so that your solution can be successfully tested. Also, don't forget to multiply the sum of time by 2.

Everything was clear?

Section 1. Chapter 3
toggle bottom row
some-alt