I have this query : http://pastebin.com/JNx1hX1i
I want to add new 2 column to my query.OldLat(Lat of 5 minutes ago),OldLat(Lng of 5 minutes ago)
Result is like this
LatOfTruck LngOfTruck SpeedOfTruck LastTime PlateOfTruck
36.9573 27.8099 72 11.12.2013 12:30:00 123456
34.9573 27.5053 82 11.12.2013 11:30:00 541456
38.8952 37.7855 52 11.12.2013 10:30:00 78455
. . . . .
. . . . .
. . . . .
Query:
SELECT LatOfTruck = TruckLocation.Lat,
LngOfTruck = TruckLocation.Lng,
SpeedOfTruck = TruckLocation.Speed,
LastTime = CONVERT(VARCHAR(10), [TruckLocation.ReadTime], 104) +
' ' + CONVERT(VARCHAR(8), [TruckLocation.ReadTime], 108),
PlateOfTruck = Trucks.Plate
FROM TruckLocation
JOIN Truck AS Trucks
ON Trucks.OID = TruckLocation.TruckID
WHERE TruckLocation.OID
IN (SELECT MAX(TruckLocation_1.OID) AS OID
FROM TruckLocation AS TruckLocation_1
JOIN Truck
ON TruckLocation_1.TruckID = Truck.OID
GROUP BY TruckLocation_1.TruckID)
ORDER BY TruckLocation.ReadTime DESC
After add OldLat and OldLng result to be like this :
LatOfTruck LngOfTruck SpdOfTruck LastTime PlateOfTruck OldLat OldLng
36.9573 27.8099 72 date 123456 LatOf5mAgo LngOf5mAgo
34.9573 27.8099 82 date 121456 LatOf5mAgo LngOf5mAgo
38.8952 37.7855 52 date 78455 LatOf5mAgo LngOf5mAgo
. . . . . . .
. . . . . . .
. . . . . . .
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…