下面示例为了说明:NVL(NULLIF(A.SICKBEDID,-1), B.SICKBEDID) 等效于 DECODE(A.SICKBEDID,-1, B.SICKBEDID, A.SICKBEDID)
SELECT NVL(NULLIF(A.SICKBEDID,-1), B.SICKBEDID), DECODE(A.SICKBEDID,-1, B.SICKBEDID, A.SICKBEDID), a.*, b.*
FROM (SELECT ENCOUNTERID, SICKBEDID , ORDERREQUESTID, ORDERDATE, COMBINEDMEDICATIONREQUESTID, SUM(Amount) AS Amount,Max(REPEATNUMBER) AS REPEATNUMBER, Max(RouteId) AS RouteId, Max(AuthorId) AS AuthorIdFROM PORX.APPLICATIONMEDICINEGROUP BY ENCOUNTERID, SICKBEDID, ORDERREQUESTID, ORDERDATE, COMBINEDMEDICATIONREQUESTID) A INNER JOIN PRPA.ENCOUNTER B
ON A.ENCOUNTERID = b.ENCOUNTERID;