sql exists 总结

select t1.code as bossgroupid
       t2.code as bosslevelid,
       t3.id   as grouplevelid,
       t5.id   as batchid
  from bossgroup     t1,
       bosslevel     t2,
       co2grouplevel t3,
       co2group      t4,
       co2cardbatch  t5
 where    t1.code='?' and t2.code='?'  and 
 t3.userlevelid = t2.userlevel and t3.groupid = t4.id and//视图1不在视图2中
       t4.grouptypeid = t1.grouptype and t5.id = 3 and not exists
 (select t6.bossgroupid, t6.bosslevelid, t6.grouplevelid, t6.batchid
          from co2bosstolevel t6
         where t1.code = t6.bossgroupid and t2.code = t6.bosslevelid and
                t5.id = t6.batchid)

 

你可能感兴趣的:(sql)