SELECT with months detail (both existing and non-existent)

1

I am currently using two tables "vehicles"

and "expenses"

of which I try to generate a detail by month of the total expenses of each vehicle between a range of dates, for this I have made the following query:

SELECT v.vehiculo, SUM(g.total), MONTHNAME(g.fecha), YEAR(g.fecha) FROM vehiculos v INNER JOIN gastos g ON v.idvehiculo = g.idvehiculo WHERE g.fecha BETWEEN '2017-12-01' AND '2018-04-01'
GROUP BY v.vehiculo,MONTHNAME(g.fecha), YEAR(g.fecha)

Which returns the following values:

However some vehicles such as "Metro" and "Riviera" have no registered expenses for the month of "February" I would like to show those months where there were no records with a value "0.00" so that all vehicles have the same interval of months with or without registered expenses for that month.

I appreciate your help beforehand!

    
asked by josemartinez 23.04.2018 в 05:13
source

0 answers