0
Amigos.
I am having difficulty recovering the most current mileage of a vehicle when it arrives at the company. The identification of the tuple is by the date of arrival of the vehicle in the company.
At the moment I have the following SQL
:
select relatorio_viagem_veiculo.referencia_veiculo, MAX(relatorio_viagem.data_chegada) from relatorio_viagem inner join relatorio_viagem_veiculo on( relatorio_viagem.id_relatorio_viagem = relatorio_viagem_veiculo.id_relatorio_viagem ) where relatorio_viagem_veiculo.referencia_veiculo = '246' and relatorio_viagem.data_saida between '2017-03-01' and '2017-03-31' group by relatorio_viagem_veiculo.referencia_veiculo, relatorio_viagem.data_chegadaorder by relatorio_viagem.data_chegada desc;
And return me the following result:
I would like you to return to me the most current record, namely:
I hope I have explained well what I desire. I thank you for your help!
ERROR: "reporter_trip.arrival date" column should appear in the GROUP BY clause or be used in an aggregation function LINE 14: reporter_trip.arrivals DESC;
– Bruno Duarte
@Brunoduarte, the mistake must be because of
order by
, i edited my answer, try again with the new code, with reference to index 2.– Camilo Santos
worked perfectly. Thank you!
– Bruno Duarte