4. Non-Correlated Subqueries - III / GROUP BY

Link: Here

I do not understand why we still have more than 7 line if we write GROUP 2,3 in the code. Why there is not only one row per day?

@bytejumper36733,
Please give us the FULL code you are using…

Sorry, I talked about the code of the example.

Here it is:

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 ) AS a GROUP BY 1,2 ORDER BY 1,2;

That’s what I’m using too, is this correct?

I really would like an answer…
If I am not clear, please let me know.

When I run the query I get only one row per day,

dep_month dep_day_of_week average_distance
2000-01 Monday 1302.0
2000-01 Saturday 328.0
2000-01 Sunday 691.333333333333
2000-01 Thursday 1805.0
2000-01 Tuesday 1410.0
2000-01 Wednesday 280.0
2000-02 Friday 1449.0

could you explain please.

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