Course Content
Intermediate SQL
Intermediate SQL
Total 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 a metro_travel_time
table.
Suppose we need to find the line with the most stations.
For this, we can use the following query:
SELECT line_name, COUNT(station_name) AS station_count FROM metro_travel_time GROUP BY line_name ORDER BY station_count DESC
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:
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.
Thanks for your feedback!
Total 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 a metro_travel_time
table.
Suppose we need to find the line with the most stations.
For this, we can use the following query:
SELECT line_name, COUNT(station_name) AS station_count FROM metro_travel_time GROUP BY line_name ORDER BY station_count DESC
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:
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.
Thanks for your feedback!
Total 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 a metro_travel_time
table.
Suppose we need to find the line with the most stations.
For this, we can use the following query:
SELECT line_name, COUNT(station_name) AS station_count FROM metro_travel_time GROUP BY line_name ORDER BY station_count DESC
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:
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.
Thanks for your feedback!
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 a metro_travel_time
table.
Suppose we need to find the line with the most stations.
For this, we can use the following query:
SELECT line_name, COUNT(station_name) AS station_count FROM metro_travel_time GROUP BY line_name ORDER BY station_count DESC
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:
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.