Sure, I'm sorry I pasted all the code in. I would like to make these two queries into one if possible. I'm a newbie and don't know much about either php or sql queries.
Query1 : Get the first fill up of the tank in June 2014
SELECT d.vehicle_id, d.liter FROM diesel AS d LEFT OUTER JOIN members AS m
ON m.id = d.userid WHERE YEAR(dato) = 2014 AND MONTH(dato) = 06 AND d.liter > 0 AND m.atruck = d.vehicle_id GROUP BY d.userid
Query2: Calculate average fuel consumption for June 2014 - To make the calculation right I need to subtract the $FirstFill variable from the total amount of fuel used in June.
SELECT m.username, m.id, 10 * (SUM(d.liter) - $FirstFill) / (MAX(d.km) - MIN(d.km)) as AvgFuel FROM members AS m
JOIN diesel AS d
ON d.userid = m.id
WHERE YEAR(dato) = 2014 AND MONTH(dato) = 06 AND d.liter > 0 AND m.atruck = d.vehicle_id
BY m.id ORDER BY AvgFuel ASC
I need to subtract the value I get in the first query with the SUM in the second.