mysql - 通过给出错误将三个表与组连接起来

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

数据库中有三个表usersorganization_entriesuser_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/

相关文章:

python - Sqlalchemy 重复条目

Mysql 返回一个不正确的 bigint 结果,非常奇怪的错误

python - MySQL 查询 - 选择具有 2 个特定 DISTINCT 列值的 2 行

php - 在php中使用查询时出现语法错误

javascript - 如何在 Postgresql 中进行批量插入并避免重复

python - 使用 Python 运行的查询不在 MySQL 中执行 unixtime 函数

sql - 如何在Sqlite3中连接来自同一个表的不同列的两个值?

database - Elastic Search 作为持久数据库

php - 每周从多个表中获取唯一数据

mysql - 在 MySQL 中混合 MATCH AGAINST 与 JOINO