2012-03-16 80 views
0

我似乎無法通過搜索我如何將能夠從下面的子查詢返回一些列的發現。特別是B.TAP_STAT_HSL/C.TAP_STAT_HSL。我不確定我是否應該加入,但任何幫助將不勝感激。甲骨文子查詢(子查詢顯示列)

SELECT 

    A.HSE_KEY_HSE AS HOUSEKEY, 
    A.DROP_STAT_HSE AS DROPSTATUS 
    A.TAP_STAT_HSL AS ITAPSTAT 

    FROM OPS$SEA.HSE_BASE,OPS$SEA.HSL_LOB,OPS$SEA.OOR_ORDER_OPEN A 

    WHERE A.HSE_KEY_HSE = A.HSE_KEY_HSL 
    AND A.HSE_KEY_HSL = A.HSE_KEY_OOR 
    AND A.DROP_STAT_HSE = '1' 
    AND A.LOB_IND_HSL = 'I' 
    AND A.TAP_STAT_HSL IN ('0','2') 
    AND A.ORD_STAT_OOR <> 'O' 
    AND EXISTS (SELECT 1 

    FROM OPS$SEA.HSE_BASE B,OPS$SEA.HSL_LOB B, OPS$SEA.OOR_ORDER_OPEN B 

    WHERE A.HSE_KEY_HSE = B.HSE_KEY_HSE 
    AND B.HSE_KEY_HSE = B.HSE_KEY_HSL 
    AND B.HSE_KEY_HSL = B.HSE_KEY_OOR 
    AND B.DROP_STAT_HSE = '1' 
    AND B.LOB_IND_HSL = 'C' 
    AND B.TAP_STAT_HSL IN ('0','2') 
    AND B.ORD_STAT_OOR <> 'O') 
    AND EXISTS (

    SELECT 1 

    FROM OPS$SEA.HSE_BASE C,OPS$SEA.HSL_LOB C, OPS$SEA.OOR_ORDER_OPEN C 

    WHERE A.HSE_KEY_HSE = C.HSE_KEY_HSE 
    AND C.HSE_KEY_HSE = C.HSE_KEY_HSL 
    AND C.HSE_KEY_HSL = C.HSE_KEY_OOR 
    AND C.DROP_STAT_HSE = '1' 
    AND C.LOB_IND_HSL = 'T' 
    AND C.TAP_STAT_HSL IN ('0','2') 
    AND C.ORD_STAT_OOR <> 'O')} 
+0

不能從子查詢我是affraid選擇... – Aprillion 2012-03-16 21:01:38

+0

什麼應該返回如果兩個'0'和'2'值出現在表B和/或C? – Aprillion 2012-03-16 21:02:36

+0

你問,如果你可以選擇從你的'exists'子查詢什麼?不,但你可以把它們變成連接,然後你可以...... – Ben 2012-03-16 21:59:10

回答

0

嗯....

相信查詢可重新編寫如下:

WITH Allowed_Rows (houseKey, dropStatus, ipApStat, indicator) 
        as (SELECT a.HSE_KEY_HSE, a.DROP_STAT_HSE, 
           b.TAP_STAT_HSL, b.LOB_IND_HSL 
         FROM OPS$SEA.HSE_BASE as a 
         JOIN OPS$SEA.HSL_LOB as b 
         ON b.HSE_KEY_HSL = a.HSE_KEY_HSE 
         AND b.LOB_IND_HSL IN ('I', 'C', 'T') 
         AND b.TAB_STAT_HSL IN ('0', '2') 
         JOIN OPS$SEA.OOR_Order_Open as c 
         ON c.HSE_KEY_OOR = a.HSE_KEY_HSE 
         AND c.ORD_STAT_OOR <> '0' 
         WHERE a.DROP_STAT_HSE = '1') 
SELECT houseKey, dropStatus, ipApStat 
FROM Allowed_Rows as a 
WHERE a.indicator = 'I' 
AND EXISTS (SELECT '1' 
      FROM Allowed_Rows as b 
      WHERE b.houseKey = a.houseKey 
      AND b.indicator = 'C') 
AND EXISTS (SELECT '1' 
      FROM Allowed_Rows as b 
      WHERE b.houseKey = a.houseKey 
      AND b.indicator = 'T') 

你沒有正確的資格你的一些表格,並用針對多個表的(我很驚訝,沒有生成語法錯誤)相同的別名,所以我必須讓我的最佳猜測,事情實際上屬於。根據其他(未列出的)要求和限制條件,還有其他一些變體可能。

爲什麼和怎麼做,你需要返回的TAP_STAT_HSL的「其他」值?你需要所有可能的組合嗎?該行對BCA代替的價值?什麼?