0
How to do the correct subtraction of these two columns in the SQL script?
SELECT DISTINCT b.prefixo as idVeiculo,
max(datatroca) as datatroca,
max(kmtroca) as kmtroca,
max(horimetroca) as horimetroca,
max(proximatroca) as proximatroca,
max(c.horimetro) as horimetroatual,
(a.proximatroca - c.horimetro) as Falta,
idMecanico FROM oleomotor a
JOIN veiculos b on (a.idVeiculo=b.idVeiculo)
JOIN hodometro c on (a.idVeiculo=c.idVeiculo)
GROUP BY a.idVeiculo order by datatroca DESC;
Possible duplicate of How do I subtract and display the result in the MYSQL query
– Costamilam
follow the consultation
– Diogo Carvalho
SELECT DISTINCT b.prefixo as idVeiculo, max(datatroca) as datatroca, max(kmtroca) as kmtroca, max(horimetroca) as horimetroca, max(proximatroca) as proximatroca, max(c.horimetro) as horimetroatual, (a.proximatroca - c.horimetro) as horarestantes, idMecanico FROM oleomotor a
JOIN vehicles b on (a.idVeiculo=b.idVeiculo) JOIN hodometro c on (a.idVeiculo=c.idVeiculo) GROUP BY a.idVeiculo order by datatroca DESC;
– Diogo Carvalho
That solves? -->
(max(a.proximatroca) - max(c.horimentro) as Falta)
– Paulo Ricardo
did not resolve...
– Diogo Carvalho