Non-Correlated Sub queries III

Can someone please explain me this code? Why do we need dep_date here?What do we mean by Group By 1,2,3?Why do we need a?

```

SELECT a.dep_month,
a.dep_day_of_week,
AVG(a.flight_distance) AS average_distance
FROM (
SELECT dep_month,
dep_day_of_week,
dep_date,
SUM(distance) AS flight_distance
FROM flights
GROUP BY 1,2,3
) a
GROUP BY 1,2
ORDER BY 1,2;

<do not remove the three backticks above>

maybe reading
Non-Correlated Subqueries III
will help

Will check,
thanks leonhard

I also wanted to ask why is it necessary to make an alias name for columns in sub queries?

those “column alias names” are then used as header in your selection-list…

i also wanted to ask the same thing…why do we need dep-date in the subquery?

Maybe this helps
4. Non-Correlated Subqueries III
found with google search
dep-date site:codecademy.com

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