Tilføj en ORDER BY til din SQL select-sætning
ORDER BY odometer ASCENDING
REDIGER
OKAY! Jeg tror, jeg forstår dit problem nu.
SELECT t1.truck_id,
t1.odometer AS km1,
MIN(t2.odometer) AS km2
FROM fueldispensed AS t1,
fueldispensed AS t2
WHERE t2.truck_id = t1.truck_id
AND T2.odometer > t1.odometer
ORDER BY t1.truck_id,
t1.odometer
GROUP BY t1.truck_id,
t1.odometer
Bør give dig noget, der vil fungere, men ikke så effektivt, som det kunne være
Rediger dit truck_id-valg i forespørgslen efter behov