I have a table with product code and date of sale. I would like to make a select picking the product code, the date of the last sale and the date of the next-to-last sale with group by code. Is it 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;