Why can't I do as below, and what is the best alternative?
SELECT year,
category,
name,
COUNT() OVER (PARTITION BY name) AS count
FROM nobel_prizes
WHERE count = 2
ORDER BY count DESC
I'm getting:
(sqlite3.OperationalError) misuse of aliased window function count
If I filter on something else than the column values for the aggregate function, it works. Can someone provide an example that illustrates why they might have prohibited doing the latter? Would it allow for bad stuff to happen?
This is happening in jupyter notebook using ipython-sql.
Note: I have seen questions on using window functions in WHERE-clauses, but not the other way around.
I'm new to SQL, be nice!
Standard SQL disallows references to column aliases in a
WHEREclause. This restriction is imposed because when theWHEREclause is evaluated, the column value may not yet have been determined.Instead, you can do it as follows: