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 an employees
table.
Suppose we need to find the department with the highest average monthly salary.
For this, we can use the following query:
SELECT department, AVG(salary) / 12 AS average_monthly_salary FROM employees GROUP BY department ORDER BY average_monthly_salary 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.
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?
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 an employees
table.
Suppose we need to find the department with the highest average monthly salary.
For this, we can use the following query:
SELECT department, AVG(salary) / 12 AS average_monthly_salary FROM employees GROUP BY department ORDER BY average_monthly_salary 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.
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?
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 an employees
table.
Suppose we need to find the department with the highest average monthly salary.
For this, we can use the following query:
SELECT department, AVG(salary) / 12 AS average_monthly_salary FROM employees GROUP BY department ORDER BY average_monthly_salary 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.
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?
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:
SELECT department, AVG(salary) / 12 AS average_monthly_salary FROM employees GROUP BY department ORDER BY average_monthly_salary 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.