Chris So
Nov 11, 2020

--

QUALIFY filters the results on basis of your window function. I am using Snowflake, which supports this. Teradata makes use of this as well.

I append the QUALIFY-statement at the end of my queries and it improves readability in two ways:

1. It's listed after HAVING, as a third filter-clause, which makes its use quite logical and thus, user-friendly.

2. It spares a nested query, caused by ROW_NUMBER, if removing duplicates.

As far as I can tell it's comparable to the FILTER-clause (PostgreSQL and SQLite). But that one can be used in the SELECT-statement only (pls correct me if I'm wrong here).

--

--

Chris So
Chris So

Written by Chris So

Data Dude and SQL enthusiast. Occasionally does Pixel art◾

Responses (1)