SQL Non-correlated Subqueries III

Hi there - I’m having a hard time understanding the code presented to me vs. the code I wrote on my own to answer the question.

Code this: How many flights are there on average for all Fridays in a given month

My code:
((
SELECT dep_month,
AVG (count_friday_flights) AS avg_fri_flights
FROM (
SELECT dep_month,
COUNT (*) AS count_friday_flights
FROM flights
WHERE dep_day_of_week = ‘Friday’
GROUP BY dep_month)
group by dep_month;
))

CodeAcademy’s code:
((
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;
)0

I think my code is a little simpler - but am I breaking any rules? Why would I use the other code? Am I missing something?

Thanks!
Val

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