i have a table consist of Truck Id & Mileage where Truck ID can be duplicated (trips). I want a query that shows the Max(mileage)-Min(Mileage) but only if the count of Truck Id > 1. Excuse me i am still a beginner in this world.
2 Answers
Try to use GROUP BY ... HAVING:
SELECT MAX(mileage)-MIN(Mileage), Truck_Id
FROM YourTable
GROUP BY Truck_Id
HAVING COUNT(Truck_id) > 1
A little tutorial with examples on the HAVING clause you find here: http://www.w3schools.com/sql/sql_having.asp