Hi, I'm trying to follow the course, had no problem to understand the first sections but suddenly we've jumped to giving tables aliases and stuff without explaining why.
I was doing Section 3 of non-correlated subqueries and I was allowed to pass the section before I'd even properly attempted the query. Can anyone tell me if the below query is correct? I don't want to pass the section without getting it right..
SELECT a.dep_month, a.dep_day_of_week, AVG(a.distance) AS average_distance FROM ( SELECT dep_month, dep_day_of_week, dep_date, distance, COUNT(*) AS flight_distance FROM flights GROUP BY 1,2,3 ) a GROUP BY 1,2 ORDER BY 1,2;
The output appears to be correct, but I'm not sure
dep_month dep_day_of_week average_distance 2000-01 Monday 1302.0 2000-01 Saturday 328.0 2000-01 Sunday 691.333333333333