数据库中有三个表users
、organization_entries
和user_invoices
,我试图连接这三个表,我的查询有点像这样
从用户 INNER JOIN user_invoices ON users.id = user_invoices.customer_id INNER JOIN on users.id =organization_entries.user_id GROUP BY 中选择 users.id 、 sum(user_invoices.due_amount) 、organization_entries.id、organization_entries.createdAt 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
我无法理解我哪里做错了。
最佳答案
按如下方式更新查询,第二个内部联接中缺少表
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 ;
关于mysql - 通过给出错误将三个表与组连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49002663/