我只是无法弄清楚这种语法有什么问题。我在最后一行收到 #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
我尝试使用 RIGHT 和 LEFT JOINS 加入表以查看是否存在差异,但它们给了我同样的错误。内部的不同查询本身可以正常工作,但是当我在此查询中将它们连接在一起时,会出现语法错误。有谁知道我应该或不应该做什么?
错误:“#1064 - 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 21 行的 '' 附近使用”