通过给出错误将三个表与组连接

Join three tables with group by giving error

数据库中有三个表 usersorganization_entriesuser_invoices,我正在尝试连接这三个表,我的查询有点像这样

select users.id , sum(user_invoices.due_amount) , organization_entries.id, organization_entries.createdAt from users INNER JOIN user_invoices ON users.id = user_invoices.customer_id INNER JOIN on users.id = organization_entries.user_id GROUP BY users.id ORDER BY organization_entries.createdAt;

但是我一次又一次地收到这个错误 -

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'on users.id = organization_entries.user_id GROUP BY users.id ORDER BY organiza' at line 1

我无法理解我哪里做错了。

按如下方式更新查询,您在第二个内部联接中缺少 table

select users.id , sum(user_invoices.due_amount) , organization_entries.id, 
organization_entries.createdAt 
from users INNER JOIN user_invoices ON users.id = user_invoices.customer_id 
INNER JOIN organization_entries ON users.id = organization_entries.user_id 
GROUP BY users.id ORDER BY organization_entries.createdAt ;