将 Oracle SQL Select 转换为 PostgreSQL select

发布于 2024-08-21 04:38:38 字数 752 浏览 5 评论 0原文

我有这样的 SQL 语句:

SELECT ABX.ABX_APO_NUMBER,
       COUNT(A1.PROCESS_MODE) AS NUM_PLANNING,
       COUNT(A2.PROCESS_MODE) AS NUM_SETUP,
       COUNT(A3.PROCESS_MODE) AS NUM_OUTPUT
  FROM ABX, USER_INSTANCE U, ACTIVE_PROCESS A1,
       ACTIVE_PROCESS A2, ACTIVE_PROCESS A3
 WHERE U.ABX_APO_NUMBER (+) = ABX.ABX_APO_NUMBER
   AND A1.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A1.PROCESS_MODE (+)= 'PLANNING'
   AND A2.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A2.PROCESS_MODE (+) = 'SETUP'
   AND A3.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A3.PROCESS_MODE (+) = 'OUTPUT'
 GROUP BY ABX.ABX_APO_NUMBER

The (+) is Causeing Fits for PG...我可以删除它们吗?它会意味着同样的事情吗? Postgres 能理解的等价物是什么?

I have this SQL statement:

SELECT ABX.ABX_APO_NUMBER,
       COUNT(A1.PROCESS_MODE) AS NUM_PLANNING,
       COUNT(A2.PROCESS_MODE) AS NUM_SETUP,
       COUNT(A3.PROCESS_MODE) AS NUM_OUTPUT
  FROM ABX, USER_INSTANCE U, ACTIVE_PROCESS A1,
       ACTIVE_PROCESS A2, ACTIVE_PROCESS A3
 WHERE U.ABX_APO_NUMBER (+) = ABX.ABX_APO_NUMBER
   AND A1.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A1.PROCESS_MODE (+)= 'PLANNING'
   AND A2.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A2.PROCESS_MODE (+) = 'SETUP'
   AND A3.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A3.PROCESS_MODE (+) = 'OUTPUT'
 GROUP BY ABX.ABX_APO_NUMBER

The (+) is causing fits for PG... Can I just remove those and it will mean the same thing? What would be the equivalent that Postgres would understand?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神爱温柔 2024-08-28 04:38:38

以下是使用 ANSI-92 JOIN 语法重写的查询:

  SELECT a.abx_apo_number,
         COUNT(ap1.process_mode) AS NUM_PLANNING,
         COUNT(ap2.process_mode) AS NUM_SETUP,
         COUNT(ap3.process_mode) AS NUM_OUTPUT
     FROM ABX a
LEFT JOIN USER_INSTANCE u ON u.abx_apo_number = a.abx_apo_number
LEFT JOIN ACTIVE_PROCESS ap1 ON ap1.process_instance_number = u.instance_number
                            AND ap1.process_mode = 'PLANNING'
LEFT JOIN ACTIVE_PROCESS ap2 ON ap2.process_instance_number = u.instance_number
                            AND ap2.process_mode = 'SETUP'
LEFT JOIN ACTIVE_PROCESS ap3 ON ap3.process_instance_number = u.instance_number
                            AND ap3.process_mode = 'OUTPUT'
 GROUP BY a.abx_apo_number

(+) 是 Oracle 特定的 LEFT OUTER JOIN 语法。要删除它,需要每个 USER_INSTANCE.instance_number 必须具有全部三种处理模式的值:PLANNING、SETUP 和 OUTPUT - 省略其中一项,并且 abx_apo_number 将不会显示在输出。

Here is your query re-written using ANSI-92 JOIN syntax:

  SELECT a.abx_apo_number,
         COUNT(ap1.process_mode) AS NUM_PLANNING,
         COUNT(ap2.process_mode) AS NUM_SETUP,
         COUNT(ap3.process_mode) AS NUM_OUTPUT
     FROM ABX a
LEFT JOIN USER_INSTANCE u ON u.abx_apo_number = a.abx_apo_number
LEFT JOIN ACTIVE_PROCESS ap1 ON ap1.process_instance_number = u.instance_number
                            AND ap1.process_mode = 'PLANNING'
LEFT JOIN ACTIVE_PROCESS ap2 ON ap2.process_instance_number = u.instance_number
                            AND ap2.process_mode = 'SETUP'
LEFT JOIN ACTIVE_PROCESS ap3 ON ap3.process_instance_number = u.instance_number
                            AND ap3.process_mode = 'OUTPUT'
 GROUP BY a.abx_apo_number

The (+) is Oracle specific LEFT OUTER JOIN syntax. To remove it, would require that each USER_INSTANCE.instance_number would have to have values for the process modes being all three: PLANNING, SETUP, and OUTPUT - omit one, and the abx_apo_number would not be displayed in the output.

jJeQQOZ5 2024-08-28 04:38:38

不,你不能直接删除它们!

(+) 是OUTER JOIN 的旧表示法。

例如

...
  FROM USER_INSTANCE U, ACTIVE_PROCESS A1
 WHERE A1.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A1.PROCESS_MODE (+)= 'PLANNING'
...

必须改为

...
FROM USER_INSTANCE U
LEFT JOIN ACTIVE_PROCESS A1
     ON (     A1.PROCESS_INSTANCE_NUMBER = U.INSTANCE_NUMBER
          AND A1.PROCESS_MODE = 'PLANNING'
        )
...

No, you can not just remove them!

The (+) is the old notation of an OUTER JOIN.

For example

...
  FROM USER_INSTANCE U, ACTIVE_PROCESS A1
 WHERE A1.PROCESS_INSTANCE_NUMBER (+) = U.INSTANCE_NUMBER
   AND A1.PROCESS_MODE (+)= 'PLANNING'
...

would have to be changed to

...
FROM USER_INSTANCE U
LEFT JOIN ACTIVE_PROCESS A1
     ON (     A1.PROCESS_INSTANCE_NUMBER = U.INSTANCE_NUMBER
          AND A1.PROCESS_MODE = 'PLANNING'
        )
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文