I'm having a question for the following query:
In my sales table I would like to return the sum by period of a given product. Today I'm doing it this way:
select YEAR(venda.data_venda) as Ano,
venda.codprod_venda as CodigoProduto,
produtos.descricao_prod,
MONTH(venda.data_venda) as Mes,
SUM(venda.qntdporprod_venda) as QtdVendida
FROM venda, produtos WHERE venda.codprod_venda = produtos.codigo_prod and produtos.codigo_prod=1
GROUP BY YEAR(data_venda), cod_prod_venda, MONTH(data_venda)
ORDER BY YEAR(data_venda), cod_prod_venda, MONTH(data_venda)
This select returns the sum of a given product per month, not per period. But in my case, I need to make the sum in the period of 30 days, for example 05.09.2015 and the search was done from 04.09.2015 until 03.10.2015 and then 04.10.2015 until 03.11.2015 and so on. I do not know if it is possible to perform this select, I would like an opinion.
Thank you!