2013-02-01 162 views
1
SELECT DISTINCT x1.NUM_KANBAN_ID ID, 
       TO_CHAR(x1.DT_CREATE,'YYYY-MM-DD') CREATED, 
       x5.TXT_PLANT_CD CD, 
       TO_CHAR(x4.DT_FIRST_VIEWED,'YYYY-MM-DD') VIEWED, 
       TO_CHAR(x4.DT_DUE,'YYYY-MM-DD') DUE, x4. 
       TXT_SHUTTLE_NUMBER SHUTTLE, 
       (select count(*) 
       from WEDI_ASN_TO_DIMENSION t8 
       where t8.TXT_MATCH_CD='1' 
       AND t8.NUM_DIMENSION_ID=x2.NUM_DIMENSION_ID AND t8.NUM_MATCH_ID = x1.NUM_KANBAN_ID) ASN, 
       x1.TXT_JIT_CALL_NUM, 
       x2.NUM_VENDOR_ID VENDOR_ID 
FROM WEDI_KANBAN x1, WEDI_DIMENSION x2, WEDI_USER_VENDORS x3, WEDI_KANBAN_TO_DIMENSION x4, WEDI_PLANT x5 
WHERE x5.NUM_PLANT_ID = x2.NUM_PLANT_ID AND 
     x1.TXT_STATUS_CD = 'C' AND 
     x2.NUM_VENDOR_ID = x3.NUM_VENDOR_ID AND 
     x4.NUM_DIMENSION_ID = x2.NUM_DIMENSION_ID AND 
     x1.NUM_KANBAN_ID = x4.NUM_KANBAN_ID AND 
     x1.DT_CREATE < SYSDATE - 15 AND 
     x5.TXT_PLANT_CD LIKE '%' AND 
     x2.TXT_MATERIAL_NUM LIKE '%' AND 
     ((x4.TXT_SHUTTLE_NUMBER IS NULL) OR (x4.TXT_SHUTTLE_NUMBER LIKE '%')) AND 
     x4.DT_DUE < SYSDATE - 10 
ORDER BY VENDOR_ID 

在上述查詢中,我應該顯示其ASN只有1或2的ID。如果ASN有這樣的0,1,2我不應該顯示這些ID。通常如果ID的ASN有0我不應該顯示。 PLS建議Sql篩選選擇

+0

eeerrrrrrrrrrrrr .....哪個字段保存ASN? –

+0

hihi,是'select'子句中的子查詢:))) –

回答

1

最簡單的解決方法是:

select * 
from (your query) 
where 0 not in (select ASN from (your query)) 

爲了不寫兩次查詢:

with (your query) as A 
select * 
from a 
where 0 not in (select asn from a) 

with (your query) as A 
select * 
from a 
where not exists (select * from a where asn = 0) 

然而,存在posibility重寫你的查詢在存在等於零的ASN時不返回任何行,但查詢很難理解,並且幾乎可以肯定某件事情是錯誤的,因爲你需要一個DISTINCT子句。這是不好的跡象。

0

添加類似(ASN = 1) Or (ASN = 2)在Where語句