SLQ Table Transformation #4 Code


#1

Good Day Group,

I am working on SQL: Table Transformation #4 of 7
Why is it SUM(distance) vs. AVG(distance) given the instructions say to find the average?

Learn Instructions
SELECT a.dep_month,
a.dep_day_of_week,
AVG(a.flight_count) AS average_flights
FROM (
SELECT dep_month,
dep_day_of_week,
dep_date,
COUNT(*) AS flight_count
FROM flights
GROUP BY 1,2,3
) a
GROUP BY 1,2
ORDER BY 1,2;

Correct Code:
SELECT a.dep_month,
a.dep_day_of_week,
AVG(a.flight_distance) AS avereage_distance
FROM(SELECT dep_day_of_week,
dep_month,dep_date,
SUM(distance) AS flight_distance
FROM flights
GROUP BY 1,2,3
)a
GROUP BY 1,2
ORDER BY 1,2;


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.