我对以下陈述有疑问:
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附近使用的正确语法
加入(从deposits GROUP BY flatsId中选择SELECT deposits.flatsId)
在第2行的f'
有人可以帮我吗?
最好的祝福,
Cs
最佳答案
在LEFT JOIN之前放入FROM
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