我已经成功合并了 3 个表(使用 ID),但是当我尝试添加第 4 个表时 - 输出完全混乱(值变得不切实际/错误)所以我认为我与这个事实有关,即第 4 个表有未分组的 ID,所以我需要在加入这个新表之前对它们进行分组。现在查询如下:
SELECT name, SUM(money) AS MONEY
FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
GROUP BY name
HAVING SUM(money)>500
当我加入新表时:
SELECT name, SUM(money) AS MONEY, SUM(data_from_NT1), SUM(data_from_NT2)
FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
JOIN newtable ON results.per_id = newtable.per_id
GROUP BY name
HAVING SUM(money)>500
是否可以执行命令 GROUP BY per_id:
(JOIN newtable ON results.per_id = newtable.per_id GROUP BY per_id)
在将这个新表添加到主表之前?上面的线不起作用。