-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Bug Report for https://neetcode.io/problems/sql-aggregation-execution-order
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The instructions mention that the execution order has the SELECT portion executed last, but at least a portion of the SELECT statement must be executed before last because the alias I created would not work if the execution order was how the instructions led the user to believe, check out this code snippet (that works):
SELECT country, year, SUM(gold + silver + bronze) AS total_medals
FROM olympic_medals
WHERE category != 'Gymnastics'
GROUP BY country, year
HAVING SUM(gold + silver + bronze) > 20
ORDER BY total_medals DESC
LIMIT 5;
I created an alias called total_medals in the SELECT clause, if this clause was entirely executed last then ORDER BY would not be able to reference it and I would get an error. It seems as though at least the alias portion of the SELECT clause is running before the ORDER BY clause. I am not sure how it works under the hood, just wanted to point this out in case this was confusing for any newcomers.