Non-Correlated Subqueries III; dep_date


#1


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



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;


In this exercise, I have to display the average distance flown each day of the week for each month. The code is correct, but I don't understand why. Why do I need dep_date?


#2

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