Table Transformation Non correlated subqueries explain please


#1

Table Transformations

Non correlated subqueries

Can some one please help me understand the purpose of sub queries in this example and what each precise piece of code is doing in this query by explaining what each line of the code is doing? id be really grateful :smiley:

E.G.
-Why and how is the table now named a?
-what is happening with the GROUP BY 1,2,3 -where did 123 come from what do they represent?
-also could this be done without a sub query? just using AVG()?

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;

thank you!!!


#2

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