質問

i've build a code sql code on localhost, (using XAMPP, phpmyadmin 4.1.6) and it works perfectly. but when I uploaded everything on server that uses phpmyadmin 3.5.7, the code didn't work. I am pretty sure that there is the same data and structure on both, localhost and server. when I run the code on server through phpmyadmin sql query, #1146 error appears, "Table 'solve.Invoice' doesn't exist", I am sure that it exists. is it bug of the version?

here is sql code:

SELECT Com.CompanyName,IFNULL(SUM(InvIn.total),0) as SumOfTotal, IFNULL(SUM(inc.income),0) as SumOfIncome, IFNULL(SUM(InvIn.total),0)-IFNULL(SUM(inc.income),0) as difference
FROM companies Com LEFT JOIN
Invoice Inv ON Inv.CompaniesID=Com.ID JOIN
InvoiceInput InvIn ON InvIn.InvoiceID=Inv.ID LEFT JOIN
Income inc ON inc.companyID=com.ID
GROUP BY Com.CompanyName
ORDER BY SumofTotal desc

table invoice: http://i.stack.imgur.com/cxDu8.jpg

table companies:

http://i.stack.imgur.com/R1260.jpg

役に立ちましたか?

解決

I think it's all about capitalization... try this:

SELECT com.CompanyName, IFNULL( SUM( InvIn.total ) , 0 ) 
AS SumOfTotal, IFNULL( SUM( inc.income ) , 0 ) 
AS SumOfIncome, IFNULL( SUM( InvIn.total ) , 0 ) - IFNULL( SUM( inc.income ) , 0 ) 
AS difference FROM companies com LEFT JOIN invoice Inv ON Inv.CompaniesID = com.ID 
JOIN invoiceinput InvIn 
ON InvIn.InvoiceID = Inv.ID 
LEFT JOIN income inc 
ON inc.companyID = com.ID 
GROUP BY com.CompanyName 
ORDER BY SumOfTotal DESC LIMIT 0 , 30   

他のヒント

Don't use com and Com, example

FROM companies Com LEFT JOIN
Income inc ON inc.companyID=com.ID
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top