ClickHouse/docs/en/sql-reference/statements/select/qualify.md
2024-04-22 14:37:04 +03:00

35 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
slug: /en/sql-reference/statements/select/qualify
sidebar_label: QUALIFY
---
# QUALIFY Clause
Allows filtering window functions results. It is similar to the [WHERE](../../../sql-reference/statements/select/where.md) clause, but the difference is that `WHERE` is performed before window functions evaluation, while `QUALIFY` is performed after it.
It is possible to reference window functions results from `SELECT` clause in `QUALIFY` clause by their alias. Alternatively, `QUALIFY` clause can filter on results of additional window functions that are not returned in query results.
## Limitations
`QUALIFY` cant be used if there are no window functions to evaluate. Use `WHERE` instead.
## Examples
Example:
``` sql
SELECT number, COUNT() OVER (PARTITION BY number % 3) AS partition_count
FROM numbers(10)
QUALIFY partition_count = 4
ORDER BY number;
```
``` text
┌─number─┬─partition_count─┐
│ 0 │ 4 │
│ 3 │ 4 │
│ 6 │ 4 │
│ 9 │ 4 │
└────────┴─────────────────┘
```