Grouping question


#1

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


Not an error, but I wonder. Below selection gives 4 column output. What would I adjust to make below selection group on the column 'flight_count'' first. Apparently '4' doesn't do the trick, but what does?



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


#2

Not sure what you mean by this.

If you're talking about ordering the columns for the flightcount first then try:

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

If you want to sort the results by number in the flight_count:

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

Hope this helps?


#3

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