Filter result by date

Asked

Viewed 39 times

1

My problem is, when I run the command below:

SELECT Id_produto AS Produto, Quantidade AS quantidade,
genius.vendas.data_venda AS Periodo
FROM genius.itens_venda
LEFT JOIN genius.vendas ON vendas.Id = Id_venda
WHERE `Id_produto` = 3418;

I have as return the following:

inserir a descrição da imagem aqui

but when I execute this:

SELECT Id_produto AS Produto, Quantidade AS quantidade,
genius.vendas.data_venda AS Periodo
FROM genius.itens_venda
LEFT JOIN genius.vendas ON vendas.Id = Id_venda
WHERE `Id_produto` = 3418 AND `data_venda` BETWEEN 2015-02-23 AND 2015-02-26;

Mysql does not return me any value, only the empty table with the column name:

inserir a descrição da imagem aqui

someone has a solution? and I also need to add the amount

  • Thank you very much for the answers, I discovered what was wrong trying the solution you proposed, missing the date quotes. What else of anger in TI kkk

  • 1

    It is not necessary to write an answer just to say "thank you". The best way to thank is accepting the answer that helped you. - From Review

2 answers

1


You can try specifying the date and time:

SELECT Id_produto AS Produto, Quantidade AS quantidade,
genius.vendas.data_venda AS Periodo
FROM genius.itens_venda
LEFT JOIN genius.vendas ON vendas.Id = Id_venda
WHERE `Id_produto` = 3418 AND 
`data_venda` BETWEEN "2015-02-23 00:00:00" AND "2015-02-26 23:59:59";

0

WHERE `Id_produto` = 3418 AND (`data_venda` BETWEEN 2015-02-23 AND 2015-02-26);

would not solve?

Browser other questions tagged

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