Skip to content
Advertisement

Select rows where partition meets condition (PostgreSQL)

I could not find a similar question with these characteristics, if it is duplicated I’ll close the question.

Imagine I have the following table in a PostgreSQL DB:

I would like to select all the rows where the following condition applies (I don’t know how to phrase this condition exactly, an example is way clearer) :

For all the groups in colA, check if there is a NOK in colB. If there is any NOK in the grouping, do not select any row of this group

For example, for the mentioned table, the result would be:

Any ideas on how to do this query? Simplicity would be advised.

Thanks in advance!

Advertisement

Answer

Perhaps a window function can help:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement