【问题标题】:Join three tables with group by giving error通过给出错误将三个表与组连接
【发布时间】:2018-08-06 17:53:09
【问题描述】:

数据库中有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

我无法理解我做错了什么。

【问题讨论】:

  • INNER JOIN on users.id = organization_entries.user_id 处缺少表名
  • 是的,愚蠢的错误,非常感谢

标签: mysql database join group-by sql-order-by


【解决方案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 ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多