Get ID which has two rows with specific values for one column

oracle

I have this Table

enter image description here

and would like to select only those IDs that I have as type A B only

The output table should be this table:

enter image description here

Might you be able to share an idea on how to approach this?

Best Answer

WITH cte AS ( SELECT id, type, COUNT(DISTINCT type) OVER (PARTITION BY id) cnt
              FROM table
              WHERE type IN ('A', 'B')
            )
SELECT id, type
FROM cte
WHERE cnt = 2