1

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

4

2 回答 2

1

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   
于 2014-04-28T12:46:19.003 回答
1

不要使用 com 和 Com,例如

FROM companies Com LEFT JOIN
Income inc ON inc.companyID=com.ID
于 2015-11-24T10:17:22.650 回答