select Instorage_Id,CompanyCode,CompanyNmae , Re 
from 入库主表 a
where  CompanyCode='AUN'
and exists(select 1 from from 入库明细表 where Instorage_Id=a.Instorage_Id
                                                          and SKU in ('A-1200','A-2301','E-4004')

解决方案 »

  1.   

    select distinct a.Instorage_Id,CompanyCode,CompanyNmae,Re from 入库主表 a left join 入库明细 b
    on a.Instorage_Id=b.Instorage_id and a.CompanyCode='AUN'and b.SKU in ('A-1200','A-2301','E-4004')
    where a.Instorage_Id='AUN20070602001'
      

  2.   

    select distinct a.Instorage_Id,CompanyCode,CompanyNmae,Re from 入库主表 a left join 入库明细 b
    on a.Instorage_Id=b.Instorage_id and b.SKU in ('A-1200','A-2301','E-4004')
    where a.Instorage_Id='AUN20070602001' and a.CompanyCode='AUN'
      

  3.   

    货物的SKU为 A-1200、A-2301、E-4004 入库单位为AUN20070602001的入库主表信息 ?
    为什么会是AUN20070602001
    它不是没有E-4004吗?
      

  4.   

    select Instorage_Id,CompanyCode,CompanyNmae , Re 
    from 入库主表 a
    where  CompanyCode='AUN'and 
    exists
    (select 1 from from 入库明细表 where Instorage_Id=a.Instorage_Id
     and SKU in ('A-1200','A-2301','E-4004')
      

  5.   

    select distinct a.*
    from 入库主表 a inner join 入库明细 b on a.Instorage_Id= b.Instorage_Id
    where a.CompanyCode = 'AUN' and (b.Sku = 'A-1200' or b.Sku = 'A-2301' or b.Sku = 'E-4004')
    and a.Instorage_Id = 'AUN20070602001'
    返回:
    Instorage_Id         CompanyCode CompanyNmae    Re                                                                                               
    -------------------- ----------- ------------- -----------
    AUN20070602001       AUN         康杰有限公司     备注(所影响的行数为 1 行)
      

  6.   

    或者这样:
    select distinct a.*
    from 入库主表 a inner join (
    select Instorage_Id from 入库明细 where Sku = 'A-1200' or Sku = 'A-2301' or Sku = 'E-4004') b on a.Instorage_Id = b.Instorage_Id
    where a.CompanyCode = 'AUN' and a.Instorage_Id = 'AUN20070602001'
    返回:
    Instorage_Id      CompanyCode CompanyNmae   Re                                                                                               
    ---------------- ----------- ------------ ---------
    AUN20070602001       AUN         康杰有限公司   备注(所影响的行数为 1 行)
      

  7.   

    select distinct a.*
    from 入库主表 a 
    inner join 入库明细 b on a.Instorage_Id= b.Instorage_Id
    where a.CompanyCode = 'AUN' 
    and (b.Sku = 'A-1200' or b.Sku = 'A-2301' or b.Sku = 'E-4004')
    and a.Instorage_Id = 'AUN20070602001'
      

  8.   

    方法3:
    select Instorage_Id,CompanyCode,CompanyNmae , Re 
    from 入库主表 a
    where  a.CompanyCode='AUN' and 
    exists
    (select * from 入库明细 where Instorage_Id=a.Instorage_Id
     and SKU in ('A-1200','A-2301','E-4004')) and a.Instorage_Id = 'AUN20070602001'
    返回:
    Instorage_Id      CompanyCode CompanyNmae   Re                                                                                               
    ---------------- ----------- ------------ ---------
    AUN20070602001       AUN         康杰有限公司   备注(所影响的行数为 1 行)
      

  9.   

    select distinct a.Instorage_Id,CompanyCode,CompanyNmae,Re from 入库主表 a left join 入库明细 b
    on a.Instorage_Id=b.Instorage_id and a.CompanyCode='AUN'and b.SKU in ('A-1200','A-2301','E-4004')
    where a.Instorage_Id='AUN20070602001'