供应商货品表
table tb
(
   sno varchar(10),
   gno varchar(10)
)sno为供应商号
gno为货品号
选中至少包含供应商 1 所供应的所有的商品的 供应商比如 sno=1
供应了两种货品gno = 1, gno = 2如果另有一个供货商 2供应商 供应了 gno=1
还有一个 sno= 3供应了 gno=1,gno=2,gno=3那就要求选出 sno=3

解决方案 »

  1.   

    select distinct sno 
    from tb a
    where not exists (
    select 1 from tb 
    where sno=3
    and gno not in (select gno from tb where sno=a.sno)
    )
      

  2.   

    select distinct k.sno
    from tb k join(
    select b.sno
    from (select * from tb where sno=1) t left join tb b on t.sno<>b.sno and t.gno=b.gno
    where b.gno is null) z
    on k.sno<>z.sno