Non-Correlated Sub queries III


#1

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>

#2

maybe reading
Non-Correlated Subqueries III
will help


#3

Will check,
thanks leonhard

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


#4

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


#5

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


#6

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


#7

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