2
我有一個使用WITH子句的查詢,能夠計算SQL結果中的某些標誌(IS_EMPLOYE,IS_AFFILIE)。但是我需要在不使用WITH子句的情況下找到與此查詢等效的內容,因爲執行SQL的軟件不允許使用WITH子句。 (我已經考慮過使用視圖來代替WITH子句,但我沒有權限創建或更改數據庫中的任何內容)。Oracle SQL - 不使用WITH子句獲得相同結果
這是查詢:
WITH
pty_id AS (
SELECT pty.PARTY_ID
FROM PTY_ROL_REL prr
JOIN PARTY pty ON prr.PRREL_PTY_ID = PTY.PARTY_ID
WHERE prr.PTY_ROL_REL_ID = <an ID provided by a variable>
),
affi AS (
SELECT prr.PRREL_PTY_ID,
Count(*) ISAFFILIE
FROM PTY_ROL_REL prr
JOIN PTY_ROL_STA_REL prsr
ON prr.PTY_ROL_REL_ID = prsr.PRSRE_PTY_ROL_REL_ID AND prsr.PRSRE_PTY_STA_CD = '01'
WHERE prr.PRREL_PTY_ROL_CD IN ('001','002')
GROUP BY prr.PRREL_PTY_ID
),
empl AS (
SELECT PRREL_PTY_ID,
Count(*) ISEMPLOYE
FROM PTY_ROL_REL
GROUP BY PRREL_PTY_ID
),
SELECT
PARTY.PARTY_ID PKEY_SRC_OBJECT,
ROWIDTOCHAR(PARTY.ROWID) SRC_ROWID,
PARTY.PARTY_ODS_MODF_DAT LAST_UPDATE_DATE,
decode(nvl(affi.ISAFFILIE, 0), 0, 0, 1) AS IS_AFFILIE,
decode(nvl(empl.ISEMPLOYE, 0), 0, 0, 1) AS IS_EMPLOYE
FROM PARTY
JOIN pty_id ON PARTY.PARTY_ID = pty_id.PARTY_ID
JOIN affi ON pty_id.PARTY_ID = affi.PRREL_PTY_ID
JOIN empl ON pty_id.PARTY_ID = empl.PRREL_PTY_ID;