Hvis jeg forstår det rigtigt, skal du bruge en OUTER JOIN
for at få resultater for de manglende måneder, men du skal også bruge en CROSS JOIN
for at få firmanavnet korrekt -- hvis ikke, vises det som NULL
:
SELECT months.month,
SUM(job_details.price_each*job_details.quantity) AS sum_monthly_price,
DATE_FORMAT(job.order_date, '%M') AS order_date,
customer.company_name
FROM months CROSS JOIN customer
LEFT JOIN job on job.company_id = customer.company_id
AND months.month = month(job.order_date)
LEFT job_details on job.job_id = job_details.job_id
WHERE months.month > month(date_sub(NOW(), INTERVAL 4 month))
AND months.month <= month(NOW())
AND customer.company_id = 6
GROUP BY months.month
ORDER BY months.month asc