我是一个Oracle家伙,试图将这样的查询转换为Postgres。不太了解所有语法,等等。希望有人可以提供帮助吗?
Oracle查询:
SELECT c.code, c.recommendation, s.suggested, s.sugg_by, a.approved, a.app_by FROM (SELECT code, recommendation FROM recommendations) c, (SELECT code, suggested, sugg_by FROM suggestions) s, (SELECT code, approved, app_by FROM suggestions) a WHERE c.code = s.code(+) AND c.code = a.code(+);
非常感谢
答案 0 :(得分:2)
您可以尝试使用OUTER JOIN
SELECT c.code, c.recommendation, s.suggested, s.sugg_by, a.approved, a.app_by
FROM (SELECT code, recommendation FROM recommendations) c
LEFT JOIN (SELECT code, suggested, sugg_by FROM suggestions) s on c.code = s.code
LEFT JOIN (SELECT code, approved, app_by FROM suggestions) a ON c.code = a.code
您似乎不需要使用子查询,因为您在子查询中没有执行任何操作,仅选择了原始列。您可以直接查询该表。
SELECT
c.code,
c.recommendation,
s.suggested,
s.sugg_by,
a.approved,
a.app_by
FROM recommendations c
LEFT JOIN suggestions s on c.code = s.code
LEFT JOIN suggestions a ON c.code = a.code