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

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

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

<In this course, it often helps to include a screenshot of your whole web browser – that lets everyone see what you see. If you wish to include a screenshot, add it below this line.>

<If you wish to copy/paste in your code, you can use this next section. This will allow others to copy/paste your code for testing – something that they won’t be able to do with just a screenshot.>

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”

<do not remove the three backticks above>
1 Like

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.

the ‘a’ = table name

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;

1 Like

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