是的我知道标题中有一些主题,但我真的读了所有这些主题并且无法解决问题。 我在sqlfiddle上显示了一个sql表:http://www.sqlfiddle.com/#!2/0aaf72/1
所以我想要一个这样的结果:
我的意思是我希望所有的数据都是结果,但我得到的是所有的数据,而不是系列列表中写有NULL ...这是我试过的:
SELECT sum(invoiceinput.total) as cons,
materialtype.`type`,
materialserie.serie,
companies.companyName
FROM invoiceinput JOIN
invoice ON invoiceinput.invoiceID=invoice.ID JOIN
companies ON companies.ID=invoice.companiesID JOIN
materialtype ON materialtype.ID=invoiceinput.materialTypeID LEFT JOIN
materialserie ON materialserie.ID=invoiceinput.materialTypeID
WHERE invoiceinput.materialTypeID
GROUP BY materialtype.ID, materialserie.ID, companies.ID, MONTH(21/04/2014)
ORDER BY MONTH(21/04/2014), companies.ID
答案 0 :(得分:-1)
SELECT sum(invoiceinput.total) as cons,
materialtype.`type`,
materialserie.serie,
companies.companyName
FROM invoiceinput JOIN
invoice ON invoiceinput.invoiceID=invoice.ID JOIN
companies ON companies.ID=invoice.companiesID JOIN
materialtype ON materialtype.ID=invoiceinput.materialTypeID LEFT JOIN
materialserie ON materialserie.ID=invoiceinput.materialserieID
WHERE invoiceinput.materialTypeID
GROUP BY materialtype.ID, materialserie.ID, companies.ID, MONTH(21/04/2014)
ORDER BY MONTH(21/04/2014), companies.ID
所以应该有materialserie ON materialserie.ID = invoiceinput.materialserieID而不是materialserie ON materialserie.ID = invoiceinput.materialTypeID