0

我试图找出inventory_detail 表中是否有任何订单(订单号实际上在inventory_header 上),其中在extrainfo_stores 表的store_Code 字段中根本不存在load_store 或unload_store 值。

下面的查询返回一些订单,当我在 extrainfo_stores 表中查看返回的订单时,我看到了该表中 load_store 或 unload_store 中的确切值,所以它显然不起作用......

 SELECT  bh.ord_number, bi.*
 FROM    inventory_header bh
 inner join inventory_detail bi on inventory_id = bh.inventory_id
 WHERE   NOT EXISTS
    (
    SELECT  null 
    FROM    extrainfo_stores d
    WHERE   d.ord_number = bh.ord_number
      and   bi.load_store <> d.store_code
      and   bi.unload_store <> d.store_code
    )
4

2 回答 2

1

它应该是这样的:

SELECT bh.ord_number, bi.*
  FROM inventory_header bh
 inner join inventory_detail bi on inventory_id = bh.inventory_id
 WHERE NOT EXISTS (SELECT null 
                     FROM extrainfo_stores d
                    WHERE d.ord_number = bh.ord_number
                      and (bi.load_store = d.store_code or bi.unload_store = d.store_code))
于 2013-05-30T17:06:29.160 回答
0

这是你想要的?

SELECT bh.ord_number, bi.*
 FROM  inventory_header bh
 join  inventory_detail bi 
   on  inventory_id = bh.inventory_id
 join  extrainfo_stores d
   on  d.ord_number = bh.ord_number
Where bi.load_store   <> d.store_code
   or bi.unload_store <> d.store_code
于 2013-05-30T17:51:32.197 回答