0
Good afternoon, I currently have the following code and result. I would like instead of having this result, to have only one row for each type (column 1), this row 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 just the 1st and 3rd line. Basically group this. Thank you
What is the database manager: Mysql? Oracle Database? Sql Server? other?
– José Diz
And you want to randomly choose one of the values of Vehicle and another registration value for each type?
– anonimo