Galera tenho o seguinte select:
SELECT
gm.Idaut AS IDIDA,
DATE_FORMAT(gm.Data,'%d/%m/%Y') as DATAI,
DATE_FORMAT(gm.HoraSaida,'%H:%i') as SAIDAI,
DATE_FORMAT(gm.HoraChegada,'%H:%i') as CHEGADAI,
(SELECT DATE_FORMAT(gm1.HoraSaida,'%H:%i') AS SAI_ANTES FROM guiasmov gm1 where DATE_FORMAT(gm1.HoraSaida,'%H:%i') < DATE_FORMAT(gm.HoraSaida,'%H:%i') AND gm1.Data = '2009-09-01' AND gm1.Idlinha = 13 AND gm1.Idcarro >= 1 AND gm1.Idcarro <= 200 AND gm1.Sentido = 0 ORDER BY SAI_ANTES DESC LIMIT 0,1) AS SAI1,
(SELECT DATE_FORMAT(gm2.HoraChegada,'%H:%i') AS CHEGA_ANTES FROM guiasmov gm2 where DATE_FORMAT(gm2.HoraSaida,'%H:%i') < DATE_FORMAT(gm.HoraSaida,'%H:%i') AND gm2.Data = '2009-09-01' AND gm2.Idlinha = 13 AND gm2.Idcarro >= 1 AND gm2.Idcarro <= 200 AND gm2.Sentido = 0 ORDER BY gm2.HoraSaida DESC LIMIT 1) AS CHEGA1
FROM guiasmov gm
WHERE
gm.Data = '2009-09-01' AND
gm.Idlinha = 13
AND gm.Sentido = 0
AND gm.Idcarro >= 1
AND gm.Idcarro <= 200
ORDER BY
SAIDAI ASC
Tá funcionando bem até certo momento:
“IDIDA”; “DATAI”; “SAIDAI”; “CHEGADAI”; “SAI1”; “CHEGA1”
199191; “01/09/2009”; “00:27”; “01:26”; NULL; NULL
200206; “01/09/2009”; “00:31”; “01:45”; “00:27”; “01:26”
198276; “01/09/2009”; “00:33”; “01:25”; “00:31”; “01:45”
198867; “01/09/2009”; “01:16”; “02:19”; “00:33”; “01:25”
197521; “01/09/2009”; “02:00”; “03:06”; “01:16”; “02:19”
199193; “01/09/2009”; “02:24”; “03:34”; “02:00”; “03:06”
200208; “01/09/2009”; “02:39”; “03:51”; “02:24”; “03:34”
198495; “01/09/2009”; “03:58”; “10:03”; “02:39”; “03:51” <------
199218; “01/09/2009”; “04:00”; “05:02”; “03:58”; “03:51”
198731; “01/09/2009”; “04:08”; “05:08”; “04:00”; “03:51”
199227; “01/09/2009”; “04:13”; “11:54”; “04:08”; “03:51”
198151; “01/09/2009”; “04:16”; “05:16”; “04:13”; “03:51”
O estranho é que a partir do oitavo registro ele começa a repetir o horário de chegada…
Onde posso está errando.
Valeu