What does the "a.something" in "Non-related subqueries 3" do?


#1

Hi,

could someone explain what the "a.something" does in the first lines of code in non-related subqueries 3?

Thanks!


#2

Here we have made a sub-table and given it an alias of a:

FROM (
    SELECT dep_month,
           dep_day_of_week,
           dep_date,
           COUNT(*) AS flight_count
    FROM flights
    GROUP BY 1,2,3
    ) a

Then with that in place, when you do this next bit, you are using only the data in that sub-table:

SELECT a.dep_month,
       a.dep_day_of_week,
       AVG(a.flight_count) AS average_flights

#4