I have several questions about this task:
1) why do we need an "a"?
2) why AS is not used here?
3) why do we put "a." in the first SELECT?
4) why do we need GROUP BY in inner query? it defines the way you see the output, isn`t it?
SELECT a.dep_month, a.dep_day_of_week, AVG(a.flight_distance) AS average_distance FROM ( SELECT dep_month, dep_day_of_week, dep_date, sum(distance) AS flight_distance FROM flights GROUP BY 1,2,3 ) a GROUP BY 1,2 ORDER BY 1,2;