0
I have 3 tables
Vehicles
idVeiculo | Placa | Prefixo
oleomotor
idMotor | idVeiculo | datatroca | kmtroca | horimetroca | proximatroca |idMecanico
I already have this query below that shows the result of the last changes of each vehicle without repeating the vehicle. how do I include in this query the table hodomentro that will take the last hour of each vehicle and subtract with the proximatroca and give the result of how many hours left.
SELECT DISTINCT b.prefixo as idVeiculo, max(datatroca) as datatroca, max(kmtroca) as kmtroca, max(horimetroca) as horimetroca, max(proximatroca) as proximatroca, idMecanico FROM oleomotor a
JOIN veiculos b on (a.idVeiculo=b.idVeiculo)
GROUP BY a.idVeiculo order by datatroca DESC;
Hodometre
idVeiculo | km | horimetro
timediff not working out...
– Diogo Carvalho
So the kind of field is not
DATETIME
correct?– Paulo Ricardo
is not same example number 60200
– Diogo Carvalho
I’ll send you the other post this clearer
– Diogo Carvalho
https://answall.com/questions/295453/como-fazer-a-subtract%C3%A7%C3%A3o-mysql
– Diogo Carvalho
I just looked,really timediff would never work because it only works with date time.
– Paulo Ricardo
In the table illustration presented by vc, the subtraction happens because the Missing field presents a number corresponding to subtraction of (160550 - 160180) = 370. It would be impossible to say how many hours are missing without a calculation evaluating the amount spent per km/h driven.
– Paulo Ricardo
Forget this post that Oce commented here, see the other one that I sent you the link and see if you can understand it
– Diogo Carvalho
I added the comment on the post there, see if it solves?
– Paulo Ricardo