Murali Murali - 1 year ago 66
SQL Question

PL/SQL : Filter IDs based on a condition by grouping Persons

I have a table with columns as below. I want to fetch the APP_ID, if all Persons in that application have at least one 'True' indicator in the Active Ind column.

APP_ID Act_Ind Person_Id
1000 true p11
1000 true p12
1000 false p13
2000 false a20
2000 true a20
2000 true a21
2000 true a22

vkp vkp
Answer Source

You can use a having clause.

select app_id
from tablename
group by app_id
having count(distinct person_id)=count(distinct case when act_id='true' then person_id end)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download