# Help with the example which represented in "4.non-correlated subqueries III"

the example they have given (the query was given as well, i didn’t built it myself):

as a solution to the question - “Imagine you’d like to know how many flights there are on average, for all Fridays in a given month from the flights table. First, we’d need to calculate the number of flights per day, and then we’d need to calculate the average based on the daily flight count for each day of the week”

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;

I have a few questions about the example:

1. what is the meaning of “GROUP BY 1,2,3”? where were these 1,2,3 come from? and how does it effect my set of results? (same quetions about “GROUP BY 1,2
ORDER BY 1,2” at the end of the query)
2. after running this example, It seems that the result’s set doesn’t fit what the example was supposed to be about… I’ve got a table with the average num of flight for each day every month instead of the average num for all Fridays in a given months, as they’ve asked…) - is it possible they have been mistaken? or am i getting it all wrong?

thanks a lot!!

1 Like

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