我正在尝试从Oracle转换此代码:
CREATE VIEW PLANNED AS
SELECT ASP.ASP_SPACE_NM,
SUM(MO.MO_TKR_TOTAL_OFF_SCHEDULED) "TOTAL_PLANNED"
FROM OBJECTIVE MO, SPACE ASP
WHERE ASP.ASP_SPACE_NM = MO.ASP_SPACE_NM (+)
AND MO.MO_MSN_CLASS_NM = 'EPIC'
GROUP BY ASP.ASP_SPACE_NM
致Postgres。
这两行令我困惑:
SUM(MO.MO_TKR_TOTAL_OFF_SCHEDULED) "TOTAL_PLANNED"
这和这个一样吗?
SUM(MO.MO_TKR_TOTAL_OFF_SCHEDULED) AS TOTAL_PLANNED
我不知道(+)在这一行中意味着什么:
WHERE ASP.ASP_SPACE_NM = MO.ASP_SPACE_NM (+)
答案 0 :(得分:2)
那是老派,Oracle特有的LEFT JOIN语法。您想将其替换为:
CREATE VIEW PLANNED AS
SELECT s.asp_space_nm,
SUM(o.mo_tkr_total_off_scheduled) 'total_planned'
FROM SPACE s
LEFT JOIN OBJECTIVE o ON o.asp_space_nm = s.asp_space_nm
AND o.mo_msn_class_nm = 'EPIC'
GROUP BY s.asp_space_nm
参考:
答案 1 :(得分:2)
+
表示(编辑:左)外部联接。
并且
SUM(MO.MO_TKR_TOTAL_OFF_SCHEDULED) "TOTAL_PLANNED"
确实很可能与
相同SUM(MO.MO_TKR_TOTAL_OFF_SCHEDULED) as "TOTAL_PLANNED"
如果我没记错,PostgreSQL中并不真正需要as
(尽管在我看来它更明确了)。
您可以查看Postgresql维基上的以下页面,了解更多差异:Oracle to Postgres conversion。