clause
QUALIFY
Filters after window calculations in DuckDB. PostgreSQL 17 requires a subquery or CTE for this pattern. Example target: DuckDB (current documentation; version unverified). Use only the isolated starter dataset; setup and expected results are in the batch evidence.
Formal Syntax & Structure
sql syntaxsql
SELECT expressions FROM table QUALIFY window_conditionWorking Example
Example Snippetsql
SELECT id FROM orders QUALIFY ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY amount DESC, id)=1 ORDER BY id;