I'm analyzing the code of my collegue. Found this query:
SELECT
client_id
from lib.applications
QUALIFY Row_Number() Over(PARTITION BY client_id ORDER BY closed) = 1
WHERE closed=0 and application_date > '2016-01-01'
Logically, the query should return a list of clients with active (not closed) applications. I can't uderstand, why he used QUALIFY etc..
here? The request below is simplier and returns the same:
SELECT
client_id
from lib.applications
WHERE closed=0 and application_date > '2016-01-01'
Do you have any idea, for what reason QUALIFY could be used here?
QUALIFY
is returning one row per client_id
. The more colloquial way of writing the query would be:
SELECT DISTINCT client_id
FROM lib.applications
WHERE closed = 0 and application_date > '2016-01-01';
Perhaps the author of the query checked performance and found that QUALIFY
is faster in this case (although I would doubt that). Perhaps the author was thinking of including other columns, in which case SELECT DISTINCT
would not work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.