表1:
   pilot    planemodel
  p1          727
  p1          737
  p2          747
  p1          a3000
   p1         727表2
        planemodel         
          727
           737
          a3000
pilot代表飞行员,planemodel代表飞机机型,我现在要用sql实现
查询出会驾驶全部机型的飞行员也就是表3     pilot
     p1
怎么实现

解决方案 »

  1.   

    如果表2没有重复记录的话,可以这样
    select pilot from (select distinct pilot,planemodel from 表1) 表11 having count(*)=(select count(*) from 表2) group by pilot;
      

  2.   

    select distinct pilot from 表1
    where exists
    (select * from 表2
    where 表1.planemodel=表2.planemodel);
      

  3.   

    这个也许可以:
    select t1.pilot
    from
           (SELECT t1.pilot, count(t1.pilot, t1.planemodel, t2.planemodel) count1
            from table1 t1, table2 t2
            where t1.planemodel = t2.planemodel
            group by t1.pilot, t1.planemodel, t2.planemodel) ta,
            (select count(planemodel) count2 from table2) tb
    where ta.count1 = tb.count2
      

  4.   

    select  distinct pilot from 表1 a
    where not exists
    (select * from 表2
      where not exists(
      select * from 表1 b
     where b.pilot=a.pilot and
     b.planemodel=表2.planemodel));
      

  5.   

    给出的表1中有相同的两条记录,在关系数据库中好像是不允许的吧?select pilot,count(*)from table1 groub by pilot
    having count(*)>(select count(*)from table2)