select *
  from vsdossier vr
 where 1 = 1
   and exists (select 1
          from vs vk
         where vk.visaserialno >= vr.startserialno
           and vk.visaserialno <= vr.endserialno
           and vk.flag not in ('0', '1')
           and vk.visacode = vr.visacode)题目内后面意思没看明白

解决方案 »

  1.   

    StartSerialNo-起始流水号、EndSerialNo-终止流水号   字段的值是一个区间还是什么?
      

  2.   


    select p.visacode, p.visaserialno
      from ywuser.vs p,
           (select p.visacode, p.visaserialno
              from ywuser.vs p, ywuser.vsdossier a
             where p.visacode = a.visacode
               and p.flag not in ('0', '1')
               and p.visaserialno >= a.startserialno
               and p.visaserialno <= a.endserialno) b //这个是区间的数据
     where p.visacode = b.visacode
       and p.visaserialno <> b.visaserialno
       and p.flag not in ('0', '1');这样写不可以么? 我感觉可以啊。不过最后一句and p.flag not in ('0', '1');应该不用加吧? 
      

  3.   

    where子句里用NOT BETWEEN StartSerialNo AND EndSerialNo排除区间内存在的流水号
      

  4.   


    select v.* from vs where v.flag not in ('0','1') 
    and v.VisaSerialNo not between (select v2.StartSerialNo from vsdossier v2 where v2.visacode = v.visacode) and (select v2.EndSerialNofrom vsdossier v2 where v2.visacode = v.visacode)
      

  5.   


    第一行vs后面忘加上 as v 了
      

  6.   

    select * from ywuser.vsdossier vsd
               where startserialno not in(select visaserialno 
                                            from ywuser.vs vsm
                                           where vsd.visacode = vsm.visacode
                                             and flag not in ('0', '1'))
                 and endserialno not in(select visaserialno 
                                          from ywuser.vs vsm
                                         where vsd.visacode = vsm.visacode
                                           and p.flag not in ('0', '1'))