Good afternoon, I currently have the following code and result. Instead of having this result, I would rather have only one line for each type (column 1), this line being the one whose column 4 has the highest value. If anyone can help (I'm a beginner).
SELECT DISTINCT TIPO.NOME_TIPO_MERCADORIA AS TIPO, VEI.ID_VEICULO AS IDVeiculo,
VEI.MATRICULA AS matricula, COUNT(VIA.ID_VIAGEM) AS Viagens
FROM VEICULO VEI, TIPO_MERCADORIA TIPO, VIAGEM VIA
WHERE VEI.ID_VEICULO = VIA.ID_VEICULO
AND VEI.ID_TIPO_MERCADORIA = TIPO.ID_TIPO_MERCADORIA
GROUP BY TIPO.NOME_TIPO_MERCADORIA, VEI.ID_VEICULO, VEI.MATRICULA
ORDER BY 1, 4 DESC;
/
I would like the final results to be only the 1st and 3rd line. Basically group this. Thanks