For example:
My Table:
| Accountid | Subid | Type |
|---|---|---|
| 001 | 11 | A |
| 001 | 12 | B |
| 002 | 13 | A |
| 002 | 14 | C |
| 003 | 15 | B |
| 003 | 16 | C |
How can I find all the Accountid that do not have any record with Type = A.
So the result should be:
| Accountid | Subid | Type |
|---|---|---|
| 003 | 15 | B |
| 003 | 16 | C |
Thank you!
>Solution :
WITH
check_type AS
(
SELECT
*,
MAX(
CASE WHEN type = 'A' THEN 1 ELSE 0 END
)
OVER (
PARTITION BY account_id
)
AS account_has_type_a
FROM
your_table
)
SELECT
*
FROM
check_type
WHERE
account_has_type_a = 0