-1
I need to get two results... I have a table with a total of 102 drivers and another table with the date he left to make deliveries and another with the arrival date...
I need to know which drivers are on the street and which are off duty.
The problem is that when I make a Join for the tables the result does not come as expected...
Example:
SELECT COUNT ('MOTORISTAS.CODIGO')
FROM
MOTORISTAS
WHERE
MOTORISTAS.SITUACAO = 'A' AND
MOTORISTAS.OBS LIKE '%BAÚ%' AND
MOTORISTAS.CODIGO IN (SELECT VIAGENS.ID_MOTORISTA
FROM VIAGENS
WHERE VIAGENS.ID_MOTORISTA <> 0)
ou este ...
SELECT COUNT (DISTINCT MOTORISTAS.CODIGO)
FROM
MOTORISTAS INNER JOIN VIAGENS ON MOTORISTAS.CODIGO = VIAGENS.ID_MOTORISTA
WHERE
MOTORISTAS.SITUACAO = 'A' AND
MOTORISTAS.OBS LIKE '%BAÚ%' AND
VIAGENS.ID_MOTORISTA <> 0
Both present a result of 42
What is your BDS? What does it say if it is traveling?
– Sorack
the tables are in Firebird
– Victor Andrade
Goal is two answers ,one qtos drivers are on the go and how many drivers are at home
– Victor Andrade
Okay, but you didn’t answer what I asked: How do you know if he’s traveling? Does the trip have a status or do you just delete it when it finishes one? And what is the link between the tables? The driver table has a
id_motorista
?– Sorack
Oops, yes, the Trips table has two columns for this purpose, one of the exits *when he leaves to travel and the other with his arrival... when he finishes this trip
– Victor Andrade