QUALIFY

constructsupportedQueries & DML

docs.snowflake.com ↗

In a SELECT statement, the QUALIFY clause filters the results of window functions. QUALIFY does with window functions what HAVING does with aggregate functions and GROUP BY clauses. In the execution order of a query, QUALIFY is therefore evaluated after window functions are computed. Typically, a SELECT statement’s clauses are evaluated in the order shown below: - FROM - WHERE - GROUP BY - HAVING - WINDOW - QUALIFY - DISTINCT - ORDER BY - LIMIT

Syntax

QUALIFY <predicate>

The general form of a statement with QUALIFY is similar to the following (some variations in order are allowed, but are not shown)

SELECT <column_list>
  FROM <data_source>
  [GROUP BY ...]
  [HAVING ...]
  QUALIFY <predicate>
  [ ... ]

Parameters

NameRequiredDescription
column_listThis generally follows the rules for the projection clause of a SELECT statement.
data_sourceThe data source is usually a table, but can be another table-like data source, such as a view, UDTF (user-defined table function), etc.
predicateThe predicate is an expression that filters the result after aggregates and window functions are computed. The predicate should look similar to a HAVING clause, but without the keyword HAVING. In addition, the predicate can also contain window functions. See the Examples section (in this topic) for predicate examples.

Usage notes

Parameters

column_list: This generally follows the rules for the projection clause of a SELECT statement. data_source: The data source is usually a table, but can be another table-like data source, such as a view, UDTF (user-defined table function), etc. predicate: The predicate is an expression that filters the result after aggregates and window functions are computed. The predicate should look similar to a HAVING clause, but without the keyword HAVING. In addition, the predicate can also contain window functions. See the Examples section (in this topic) for predicate examples.