Murali Murali - 11 months ago 52
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)