Этот запрос:
select col1
from tablename
where col2 in ('PC', 'PP')
group by col1
having count(distinct col2) = 2
возвращает все col1
s, которые вы хотите, и вы можете использовать его с оператором IN
:
select * from tablename
where col2 in ('PC', 'PP')
and col1 in (
select col1
from tablename
where col2 in ('PC', 'PP')
group by col1
having count(distinct col2) = 2
)
См. демо . Результатов:
| ID | COL1 | COL2 |
| --- | ---- | ---- |
| 1 | 100 | PC |
| 2 | 100 | PP |
| 6 | 300 | PC |
| 7 | 300 | PP |