oracle使用LEFT JOIN关联产生的问题在查询结果中使用CASE WHEN 无法判断
查询方式一:
1 SELECT
2 CASE WHEN (SELECT CAST(SUM(CASE
3 WHEN (ALLOCABLE_PRIME_CURRENCY_VALUE IS NULL AND STATE_IND = 1) THEN
4 NVL(PRIME_CURRENCY_VALUE, 0)
5 ELSE
6 NVL(ALLOCABLE_PRIME_CURRENCY_VALUE, 0) END) AS NUMBER(18,6)) AS ALLOCABLE_PRIME_CURRENCY_VALUE
7 FROM RP_LEDGER_ITEM R
8 WHERE R.SOURCE_ID = RP_CASH_MOVEMENT.CASH_MOVEMENT_ID
9 AND SOURCE_TYPE = ‘CASH‘) = 0 THEN 0 ELSE 1 END,
10 (SELECT SUM(CASE
11 WHEN (ALLOCABLE_PRIME_CURRENCY_VALUE IS NULL AND STATE_IND = 1) THEN
12 NVL(PRIME_CURRENCY_VALUE, 0)
13 ELSE
14 NVL(ALLOCABLE_PRIME_CURRENCY_VALUE, 0) END) AS ALLOCABLE_PRIME_CURRENCY_VALUE
15 FROM RP_LEDGER_ITEM R
16 WHERE R.SOURCE_ID = RP_CASH_MOVEMENT.CASH_MOVEMENT_ID
17 AND SOURCE_TYPE = ‘CASH‘),
18 RP_LEDGER_ITEM.LEDGER_ITEM_ID
19 FROM RP_CASH_MOVEMENT
20 LEFT JOIN RP_LEDGER_ITEM
21 ON RP_LEDGER_ITEM.CASH_MOVEMENT_ID = RP_CASH_MOVEMENT.CASH_MOVEMENT_ID
22 AND RP_LEDGER_ITEM.CASH_MOVEMENT_ID IS NOT NULL
23 WHERE NVL(RP_CASH_MOVEMENT.IS_RESERVE_FUND, ‘0‘) = ‘0‘
24 AND 1 = 1
25 AND RP_CASH_MOVEMENT.RP_ID = ‘R‘
26 AND RP_CASH_MOVEMENT.INPUT_DATE >=
27 TO_DATE(‘2014/2/1 0:00:00‘, ‘YYYY-MM-DD HH24:MI:SS‘)
28 AND (RP_CASH_MOVEMENT.OFFICE_ID = ‘0B4B12XOG33MO‘)
查询结果如下:
查询方式二:
SELECT
CASE WHEN (SELECT CAST(SUM(CASE
WHEN (ALLOCABLE_PRIME_CURRENCY_VALUE IS NULL AND STATE_IND = 1) THEN
NVL(PRIME_CURRENCY_VALUE, 0)
ELSE
NVL(ALLOCABLE_PRIME_CURRENCY_VALUE, 0) END) AS NUMBER(18,6)) AS ALLOCABLE_PRIME_CURRENCY_VALUE
FROM RP_LEDGER_ITEM R
WHERE R.SOURCE_ID = RP_CASH_MOVEMENT.CASH_MOVEMENT_ID
AND SOURCE_TYPE = ‘CASH‘) = 0 THEN 0 ELSE 1 END,
(SELECT SUM(CASE
WHEN (ALLOCABLE_PRIME_CURRENCY_VALUE IS NULL AND STATE_IND = 1) THEN
NVL(PRIME_CURRENCY_VALUE, 0)
ELSE
NVL(ALLOCABLE_PRIME_CURRENCY_VALUE, 0) END) AS ALLOCABLE_PRIME_CURRENCY_VALUE
FROM RP_LEDGER_ITEM R
WHERE R.SOURCE_ID = RP_CASH_MOVEMENT.CASH_MOVEMENT_ID
AND SOURCE_TYPE = ‘CASH‘),
‘‘ LEDGER_ITEM_ID
FROM RP_CASH_MOVEMENT
LEFT JOIN RP_LEDGER_ITEM
ON RP_LEDGER_ITEM.CASH_MOVEMENT_ID = RP_CASH_MOVEMENT.CASH_MOVEMENT_ID
AND RP_LEDGER_ITEM.CASH_MOVEMENT_ID IS NOT NULL
WHERE NVL(RP_CASH_MOVEMENT.IS_RESERVE_FUND, ‘0‘) = ‘0‘
AND 1 = 1
AND RP_CASH_MOVEMENT.RP_ID = ‘R‘
AND RP_CASH_MOVEMENT.INPUT_DATE >=
TO_DATE(‘2014/2/1 0:00:00‘, ‘YYYY-MM-DD HH24:MI:SS‘)
AND (RP_CASH_MOVEMENT.OFFICE_ID = ‘0B4B12XOG33MO‘)
查询结果如图:
2条sql语句最大的区别在于
有些可能表达不清楚,
主要原因我也不知道,如果谁有兴趣可以回复我!
oracle使用LEFT JOIN关联产生的问题在查询结果中使用CASE WHEN 无法判断,布布扣,bubuko.com
时间: 2024-10-21 17:27:48