I have just discovered BigQuery’s QUALIFY operator and have been reading about it at https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#qualify_clause
That documentation though does not explain why I should use QUALIFY instead of a normal WHERE predicate. If we take the example provided in the documentation:
SELECT item,
RANK() OVER (PARTITION BY category ORDER BY purchases DESC) as rank
FROM Produce
WHERE Produce.category = 'vegetable'
QUALIFY rank <= 3
That query could also be written as
SELECT
item,
RANK() OVER (PARTITION BY category ORDER BY purchases DESC) as rank
FROM Produce
WHERE Produce.category = 'vegetable'
AND rank <= 3
and it would produce the same result. So what is the advantage of using QUALIFY?