Condition in MySQL in data query

1

Is there any way to do a condition to show data only if the status is as aprovado in the database?

MySQL:

Nome  ProdValor   Data         Status
Goku  250,00      15/04/2015   Aprovado
Goku  250,00      15/04/2015   Pendente
Goku  250,00      15/04/2015   Cancelado

PHP

 $busca = mysql_connect("$local","$usuario","$senha") or die("ERRO AO CONECTAR AO MYSQL, VERIFIQUE COM O ADMINISTRADOR" . mysql_error());
 mysql_select_db("$banco") or die("BASE DE DADOS INVÁLIDO");
 $pesquisa = mysql_query("SELECT sum(ProdValor) FROM vendas WHERE MONTH(data) = MONTH(DATE_ADD(CURDATE(),INTERVAL -1 MONTH))");

  while($sum = mysql_fetch_array($pesquisa)){
      $soma2 = $sum['sum(ProdValor)'];
  }    

  echo $soma2;
    
asked by anonymous 16.04.2015 / 03:31

1 answer

4

Yes, it is possible. It would look something like this:

SELECT sum(ProdValor) FROM vendas
    WHERE MONTH(data) = MONTH(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)) AND Status = 'Aprovado'

As you have not given much detail, you may need some adaptation to what you will do. Ideally, the Status column would not be text.

    
16.04.2015 / 03:36