0
I have a chart with product code and date of sale. I would like to make a select by taking the product code, the date of the last sale and the date of the penultimate sale with group by code. It is possible?
select
p.codigo,
max(date_format(p.data_venda, '%d/%m/%Y')) Data_Ultima_Venda,
(max(date_format(p.data_venda, '%d/%m/%Y'))-interval 1 day) Data_Penultima_Venda
from
itens i
inner join pedidos p on p.id=i.pedido_id
group by p.codigo
order by p.data_venda DESC
limit 10;
You need to give more information about your query, post the code you were working on so it is possible to guide you to the correct answer.
– Marco Vinicius Soares Dalalba
@Marcoviniciussoaresdalalba: select p.codigo, max(date_format(p.data_sale, '%d/%m/%Y')) Data_ultima_sale, (max(date_format(p.data_sale, '%d/%m/%Y'))-interval 1 day) Data_penultima_sale from items i Inner Join requests p on p.id=i.pedido_id group by p.codigo order by p.data_sale DESC limit 10;
– Lucas Bicalho
Edith your question and add code.
– Marco Vinicius Soares Dalalba