查询订购的产品至少包含了订单1号中所订购产品的订单 不晓得这个写的对否
select distinct 订单号 from 订单表 where 订单号<>3 and 产品ID in(select 产品ID from 订单表 where 订单号=1)

解决方案 »

  1.   

    select distinct 订单号 from 订单表 where 订单号 <>3 and 产品ID in(select 产品ID from 订单表 where 订单号=1) 无语法错误。
      

  2.   

    select distinct 订单号 from 订单表 where 订单号 <>1 and 产品ID in(select 产品ID from 订单表 where 订单号=1) 应该没问题,订单号 <>3的地方时手误吧
      

  3.   

    select distinct 订单号 from 订单表 t
    where 订单号<>3
    and not exists(select 1 from 订单表 a right join 订单表 b on a.订单号=t.订单号 and b.订单号=1 and a.产品ID=b.产品ID where a.产品ID is null)
      

  4.   

    需求比较模糊  至少包含了订单1号中所订购产品的订单
    要是那样的话直接用,里面一定有订单1号
    select distinct 订单号 from 订单表
      

  5.   

    不好意思啊,<>3 这个地方的确是写错了,应该是 1,呵呵
      

  6.   

    declare @tb15 table(
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [orid] [int] NULL ,
    [prdid] [varchar] (50) 
    )insert into @tb15(orid,prdid) 
    select 1,'a' union all
    select 1,'b' union all
    select 2,'a' union all
    select 2,'b' union all
    select 2,'c' union all
    select 3,'a' union all
    select 3,'b' union all
    select 3,'a' union all
    select 4,'a'union all
    select 4,'c'union all
    select 5,'a'union all
    select 5,'b' --对订单1号的产品。查找没有不订此产品的订单,双重否定
    select distinct orid from @tb15 a where not exists (select * from @tb15 b where  orid=1  and not  exists (select * from @tb15  where  prdid=b.prdid and orid=a.orid)) and orid<>1
    orid        
    ----------- 
    2
    3
    5