2010-02-15 85 views
2

我有這樣的SQL語句:轉換的Oracle SQL SELECT INTO PosgreSQL選擇

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 

的(+)是造成千篇一律的PG ......可我只是刪除這些,這將意味着同樣的事情? Postgres會理解什麼?

回答

4

這裏是你的查詢中使用重新編寫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 - 省略1,並且abx_apo_number不會顯示在輸出中。

+0

+1爲整個方式:) – 2010-02-15 20:45:43

1

不,你不能把它們刪除! (+)是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' 
     ) 
...