I have the following table / fields:
Table: PLANS
-
ID
(PK) -
VEICULO
(REPEAT) -
DATAINCLUSAO
-
REVISAO
(UNIQUE)
I need to get the number of REVISAO
of each VEICULO
of last DATAINCLUSAO
.
So I can get VEICULO
and last DATAINCLUSAO
, but if I put REVISAO
, it will ask to add in GROUP BY
, and I can not, since REVISAO
is unique, so it would bring me everything.
If I put MAX(REVISAO)
can bring me incorrect value.
SELECT VEICULO, MAX(DATAINCLUSAO)
FROM PLANOS
GROUP BY VEICULO
In short, what I need is to get the value of REVISAO
, referring to the last DATAINCLUSAO
of each VEICULO
.