Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find the records that do not have a specific value on a different column?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading