PostgreSQL多重连接问题

huangapple go评论79阅读模式
英文:

PostgreSQL multiple join issue

问题

ERROR: 第二个INNER JOIN 语法有问题。要在第一个INNER JOIN 结束后加一个分号,然后才能开始第二个INNER JOIN。以下是修正后的代码:

  1. SELECT
  2. access.id,
  3. access.user_id,
  4. access.device_id,
  5. access.origin,
  6. access.creation_date
  7. FROM
  8. table1 access
  9. INNER JOIN (
  10. SELECT
  11. device_id,
  12. MAX (creation_date) AS creation_date
  13. FROM
  14. table1
  15. GROUP BY
  16. device_id
  17. ) gaccess ON access.device_id = gaccess.device_id
  18. AND access.creation_date = gaccess.creation_date
  19. INNER JOIN
  20. table2 AS jobinfo
  21. ON gaccess.device_id = jobinfo.id;

希望这有帮助!

英文:

Iam trying to create query with multiple JOINS, but Im receiving error message regarding syntax on second JOIN.

ERROR: syntax error at or near "INNER"
LINE 19: INNER JOIN table2 AS jobinfo ON gaccess....
^
SQL state: 42601
Character: 418

Can you help me what am I doing wrong?

  1. SELECT
  2. access.id,
  3. access.user_id,
  4. access.device_id,
  5. access.origin,
  6. access.creation_date
  7. FROM
  8. table1 access
  9. INNER JOIN (
  10. SELECT
  11. device_id,
  12. MAX (creation_date) AS creation_date
  13. FROM
  14. table1
  15. GROUP BY
  16. device_id
  17. ) gaccess ON access.device_id = gaccess.device_id
  18. AND access.creation_date = gaccess.creation_date;
  19. INNER JOIN
  20. table2 AS jobinfo
  21. ON gaccess.device_id = jobinfo.id

答案1

得分: 2

你有一个问题 - 在倒数第二个 INNER JOIN 之前有一个 ; - 你需要移除它。

  1. SELECT access.id,
  2. access.user_id,
  3. access.device_id,
  4. access.origin,
  5. access.creation_date
  6. FROM table1 access
  7. INNER JOIN
  8. (
  9. SELECT device_id
  10. ,MAX(creation_date) AS creation_date
  11. FROM table1
  12. GROUP BY device_id
  13. ) gaccess
  14. ON access.device_id = gaccess.device_id
  15. AND access.creation_date = gaccess.creation_date
  16. INNER JOIN table2 AS jobinfo
  17. ON gaccess.device_id = jobinfo.id;
英文:

You have a type - before the last INNER JOIN there is ; - you need to remove it.

  1. SELECT access.id,
  2. access.user_id,
  3. access.device_id,
  4. access.origin,
  5. access.creation_date
  6. FROM table1 access
  7. INNER JOIN
  8. (
  9. SELECT device_id
  10. ,MAX(creation_date) AS creation_date
  11. FROM table1
  12. GROUP BY device_id
  13. ) gaccess
  14. ON access.device_id = gaccess.device_id
  15. AND access.creation_date = gaccess.creation_date
  16. INNER JOIN table2 AS jobinfo
  17. ON gaccess.device_id = jobinfo.id;

huangapple
  • 本文由 发表于 2023年2月8日 15:37:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定