v.24.4New Feature

Support QUALIFY Clause Implementation

Support QUALIFY clause. Closes #47819. #62619 (Maksim Kita).
Added support for the QUALIFY clause in ClickHouse SQL queries.

Why it matters

The QUALIFY clause allows users to filter the results of window functions directly, simplifying queries that require filtering on window function results without using subqueries or additional nested SELECT statements. This enhances query readability and performance when working with analytical functions.

How to use it

Users can append the QUALIFY clause after WHERE and WINDOW clauses to filter rows based on conditions applied to window function results. For example:

SELECT column1, ROW_NUMBER() OVER (PARTITION BY column2 ORDER BY column3) AS rn
FROM table
QUALIFY rn = 1

This query selects the first row for each partition defined by column2.