MYSQL grouped query

Asked

Viewed 24 times

1

I have a table where the fields are:

  • cod_patient
  • cod_pathology
  • leading

a patient may have more than one pathology, but one must be defined as principal, need to filter which patients have no items defined as principal.

I tried the following, unsuccessfully.

select cod_cli,
    count(CASE 
            WHEN principal IS NOT NULL THEN 1
            ELSE 0
            END) AS cont_principal
from cid_cli group by cod_cli

can suggest something to me?

1 answer

2


Hello,

I believe you need to use the clasula having (which is the group by filter)

select cod_paciente from tabela group by cod_paciente having count(principal) < 1
  • Thanks, it worked out!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.