我对以下声明有疑问:
SELECT SUM(foreseen_charges.commonCharge) as required, foreseen_charges.flatsId
LEFT JOIN (SELECT deposits.flatsId FROM deposits GROUP BY flatsId) deps
ON foreseen_charges.flatsId = deps.flatsId
FROM foreseen_charges GROUP BY foreseen_charges.flatsId
我总是收到这个错误:
您的SQL语法有错误;检查对应的手册 到您的MySQL服务器版本,以便使用接近' LEFT的正确语法 JOIN(SELECT deposits.flatsId FROM deposit GROUP BY flatsId)deps 在f'在第2行
有人可以帮助我吗?
最诚挚的问候, CS
答案 0 :(得分:2)
在 LEFT JOIN
之前放置 FROMSELECT SUM(foreseen_charges.commonCharge) as required,
foreseen_charges.flatsId
FROM foreseen_charges
LEFT JOIN (
SELECT deposits.flatsId
FROM deposits
GROUP BY flatsId
) deps ON foreseen_charges.flatsId = deps.flatsId
GROUP BY foreseen_charges.flatsId
答案 1 :(得分:1)
你做的事情不按规定。一般结构是:
SELECT (something) FROM table JOIN other-table ON table.var1=other-table.var2 WHERE situation
你这样做:
SELECT (something) LEFT JOIN table ON table.var1=other-table.var2 FROM other-table
在你声明了两个表之前你不能加入,并且你不能将other-table关联起来,因为你还没有声明它。
不确定查询的目的是什么,但这应该可以修复语法错误:
SELECT SUM(foreseen_charges.commonCharge) as required, foreseen_charges.flatsId
FROM foreseen_charges
LEFT JOIN (SELECT deposits.flatsId FROM deposits GROUP BY flatsId) deps
ON foreseen_charges.flatsId = deps.flatsId
GROUP BY foreseen_charges.flatsId