How do I validate specific fields in SQL

Asked

Viewed 296 times

-1

I have the following code made by Amon:

select 
  id,
  disponibilidade,
  tipo 
from 
  clientes 
where 
  cliente = '$cliente' 
  AND status = '2' 
  AND (tipo <> '0' AND (disponibilidade <> '0'  OR vanual <> '0' OR vtemporada <> '0'))

I need him to show how many customers have a EQUAL TYPE OF ZERO and not having at least one of the camps availability OR vanual OR vtemporada filled.

Thank you very much!

  • Exchange the = for <> in diponibility, vnaul, vtemporada.

  • Try it like this: select id,disponibilidade,tipo from clientes where cliente = '$cliente' AND status = '2' AND tipo <> '0' AND (disponibilidade <> '0' OR vanual <> '0' OR vtemporada <> '0')

  • @ramaral gave no!

  • Ask the question: - The names and types of the columns used (id, availability, type, client, status, vanual and vtemporada). - Examples of lines that are supposed to show and not show and why.

  • After all it is tipo <> 0 or tipo = 0?

1 answer

-1

As you said yourself, you will use the clause AND. Your query will be as below:

select 
  COUNT(CASE WHEN tipo = 0 THEN 1 ELSE NULL END) [TIPO_ZERO],
  COUNT(CASE WHEN tipo <> 0 THEN 1 ELSE NULL END) [TIPO_DIFERENTE_ZERO]
from 
  clientes 
where 
  cliente = '$cliente' 
  AND status = '2' 
  AND (disponibilidade <> '0'  OR vanual <> '0' OR vtemporada <> '0')
  • Friend, I re-asked my question with your SQL, can help me?

  • @Gladisonneuzaperosini, I edited the answer.

  • Gave error, could not run SQL. Colei the way you posted!

  • I made the correction, removed the [TIPO_ZERO] and [TIPO_DIFERENTE_ZERO]. But the result did not match the information contained in the database.

Browser other questions tagged

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