我只是無法弄清楚這個語法有什麼問題。最後一行出現#1064語法錯誤。另一個1064語法錯誤
SELECT b.id, b.lastname, b.name, c.balance, a.maxdebt, b.warndata, b.warndownload, b.warnupload, b.warndebt, b.cutoffdata, b.cutoffdownload, b.cutoffupload, b.cutoffdebt, b.data, b.download, b.upload, b.warning, b.access, b.cutoffstop
FROM (
SELECT customers.id AS id, SUM(tariffs.value) AS maxdebt
FROM tariffs
INNER JOIN assignments ON tariffs.id = assignments.tariffid
INNER JOIN customers ON assignments.customerid = customers.id
GROUP BY id
) a
LEFT JOIN (
SELECT customers.id AS id, UPPER(lastname) AS lastname, customers.name AS name, SUM(stats.upload+stats.download) AS data, SUM(stats.download) AS download, SUM(stats.upload) AS upload, cutoffstop, warndata, warndownload, warnupload, warndebt, cutoffdata, cutoffdownload, cutoffupload, cutoffdebt, warning, access
FROM customers
LEFT JOIN nodes ON customers.id = nodes.ownerid
LEFT JOIN stats ON nodes.id = stats.nodeid
LEFT JOIN customerwarnings ON customers.id = customerwarnings.id
GROUP BY id
) b
LEFT JOIN (
SELECT customerid, SUM(cash.value) AS balance
FROM cash
GROUP BY customerid
) c ON a.id = b.id = c.customerid
我試圖聯接表與左,右連接來看看是否是有差別的,但他們給我同樣的錯誤。 工作中的不同查詢可以很好地處理它們,但是當我在查詢中將它們連接在一起時,我得到一個語法錯誤。有誰知道我應該做什麼或不應該做什麼?
的錯誤:「#1064 - 你在你的SQL語法錯誤;檢查對應於您的MySQL服務器版本在第21行使用‘’附近正確語法手冊」
我想在子查詢'B'您需要更改'GROUP BY'因爲你使用聚合'SUM'但選擇比'GROUP BY' – JScoobyCed