select distinct alternative,alt_rev from alt_item 
where 
( 0<(select count(*) From item_det id where id.nettable='Y' and id.CCN='TS0001' and (id.OH_QTY-id.COM_QTY-id.RESV_QTY)>0 AND id.item=alternative ) 
OR 
0<(select count(*) from po where PO.CLOSED_DATE is null and po.qty_ord>po.qty_rec and po.CCN='TS0001' AND po.item=alternative) ) 
AND alt_item.CCN='TS0001' AND COMPONENT='1600-0000-A1-1B' 其中where语句的()中语句的作用?以前没有碰到过请大家解释的详细点

解决方案 »

  1.   

    过滤记录,有些alternative在alt_item表中,但不满足where中的条件就要滤掉了
    where中的两处查询是以alt_item的alternative为条件查找的。
      

  2.   

    看看sql 数据嵌套查询~ where 子句包含select 语句。
      

  3.   

    比如'aaa'是alt_item表alternative字段的记录
    现在做检验
    select count(*) From item_det id where id.nettable='Y' and id.CCN='TS0001' and (id.OH_QTY-id.COM_QTY-id.RESV_QTY)>0 AND id.item='aaa'
    如果count(*) >0 这条记录就要取出来,
    同理检验
    select count(*) from po where PO.CLOSED_DATE is null and po.qty_ord>po.qty_rec and po.CCN='TS0001' AND po.item='aaa'