I have a QUERY that does not display what I really need

-5

My Query:

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

I need it to work as follows:

You may see some record if the TYPE field is other than ZERO and also at least one of the fields: availability , vanual and timesheet have some nonzero value.

In other words, to display a record the TYPE field is required to be different from ZERO and also some of the availability fields, > vanual and timeout have any non-zero value

Except that this SQL that I mounted does not do that!

I look forward to help!

    
asked by anonymous 15.03.2016 / 17:24

2 answers

1

By modifying your query, which I believe is being assigned to some variable before it is executed, try the following:

$sql = "SELECT id 
FROM clientes 
WHERE
cliente = $cliente 
AND status = 2
AND tipo <> 0 
AND (disponibilidade <> 0 OR vanual <> 0 OR vtemporada <> 0)"
    
15.03.2016 / 17:33
0

After chatting, I saw that what you really want is: If tipo is zero, it counts. If tipo is non-zero, check that the other information is zero, and it counts.

This is what you need, I think the following query returns as expected:

SELECT 
    COUNT(1) as TOTAL_CLIENTES /*Conte 1 exibindo coluna como TOTAL_CLIENTES*/ 
    FROM 
    clientes /*Da tabela de clientes*/ 
    WHERE 
    (tipo = 0 ) /* Se o tipo for zero (só ai o cadastro já está incompleto)*/
    OR (/*OU*/
        tipo <> 0 /*Existe um tipo informado*/
        AND disponibilidade = 0 /*E a disponibilidade é zero*/
        AND vvenda = 0 /* E o vvenda é zero também*/
        AND vtemporada = 0 /* E o vtemporada também é zero, caracterizando um cliente que tem um tipo mas não tem nenhuma informação de valores*/
    )

I copied the response from the other created topic.

    
15.03.2016 / 20:20