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,则不应显示。请建议

4

2 回答 2

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)

但是,当存在等于零的 ASN 时,存在重写查询以不返回任何行的可能性,但查询很难理解,并且几乎可以肯定有问题,因为您需要 DISTINCT 子句。那是个坏兆头。

于 2013-02-01T06:52:26.647 回答
0

(ASN = 1) Or (ASN = 2)在您的 Where 语句中添加类似的内容

于 2013-02-01T06:58:13.027 回答