Hi, I have a question for the “GROUP BY” clause inside subquery a. My understanding is that the subquery is obtaining the total number of flights on each date, which will be used to calculate the average in the outer query. If so, shouldn’t “GROUP BY 3” be sufficient? Why do we have to GROUP BY 1,2,3?
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