4. Non-Correlate Sub queries 2 - Is this right?


#1

Hi,
Could someone confirm if this is right, it seems to pass me but I got the error (See image) coming up on the screen.
Also what does group by 1, 2, 3 do?




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;


#2

The Group 1,2,3, groups it by the 1st, 2nd, and 3rd variables in your Select statement (dep_month, dep_day_of_week, and dep_date.

In your outer query, you group by the 1st (dep_month - from the inner query group by) and 2nd (dep_day_of_the_week)


#3

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