Non-Correllated Sub-Queries III: What is the "a." for?


#1



https://www.codecademy.com/courses/sql-table-transformation/lessons/subqueries/exercises/non-correlated-iii?action=lesson_resume


When the following code is provided in the example, what is the point of the "a." before dep_month, dep_day_of_week, and flight_count. I have attempted to look it up, but I can't find an answer anywhere. Am I missing something really simple?


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


#2

I am also stuck on this section. From a separate SQL lesson on a different site (The Stanford one, not that great btw) I think it says the a. is the abbreviation. As far as what it is abbreviating I do not know. I would also like to know.


#3

the 'a' = table name


#4

I'm also pretty confused by this exercise. For two reasons:
1. The letter a showing up.
From what I can understand it could be a way to write airports.dep_month.

It is also showing up after the closing parathese in the subquery. Is it the way to rename the whole sub-query as "a" and we then refer to it before ? I would expect a "AS" or some sort of function marker.

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

  1. The tables are grouped and ordered by integers (1,2,3). Also very unclear on this part. I thought Group would usually refer to a column. Same thing for Order.

GROUP BY 1,2
ORDER BY 1,2;

I just feel like I skipped a whole chapter of the intro (but I didn't..)

Thank you for the help, here's the full code for the exercise :

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;


#5

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