Skip to content
Advertisement

SQL logic to fail a check if any of the related customers has failed

I have the requirement to flag the customers Y only when all the related customers have also passed the check. below are the two tables:

relationship table :

Check table

I want output like below:

output justification: since 1,2,3 are related customers and since one of them (3) has n in table 2 , so all the related customers should also have n. 11,22 are related customers and both have y in table 2.so in output both should have y.

Advertisement

Answer

You need to join relationship to check and use conditional aggregation:

See the demo.

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