Hi Everyone,
Question: Is there a way to SUM the MAX in a column?
What I have is a table with an ID (incremental), VID (vehicle ID), STOPDATE (date recorded), and STOP (odometer reading).
What I want to do is take the MAX(stop) from each VID and then add them together to get a total.
If I use this:
$total_result = mysql_query("SELECT SUM(stop) as totalmiles FROM mileage GROUP BY vid");
My total comes out to be: 12,315.0
If I use this one without the grouping:
$total_result = mysql_query("SELECT SUM(stop) as totalmiles FROM mileage");
My total comes out to be: 1,112,430.3
The actual total should be: 366,210.4
Any suggestions, guidance or a piece of a script would be gratefully appreciated.
Ivan