Converting Oracle SQL Select into PostgreSQL select

后端 未结 2 1276
心在旅途
心在旅途 2021-01-20 17:40

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         


        
相关标签:
2条回答
  • 2021-01-20 18:28

    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'
            )
    ...
    
    0 讨论(0)
  • 2021-01-20 18:33

    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.

    0 讨论(0)
提交回复
热议问题