select * from kczxxb a  where ((a.Jybz = -1) or (a.Jybz= -2))
                             and ( a.Npkh In (select b.Npkh from huikb b) )

解决方案 »

  1.   


    select * from kczxxb a inner join huikb b on a.Npkh=b.Npkh and a.Jybz in(-1,-2)
      

  2.   


    create table huikb( Npkh int,  Cs int)
    insert into huikb select 123,   1  create table kczxxb(Dh varchar(20),    Npkh int,    Jybz  int)
    insert into kczxxb select   '00001',   123,      -1
    insert into kczxxb select      '00002',   321,     -2kczxxb.Jybz=-1时,如果该记录中的Npkh的值在huikb中有对应的值话,就显示kczxxb.Jybz=-1和kczxxb.Jybz=-2的两条记录,如果Npkh的值在没huikb中没有对应的值,那就不显示,
       请问如何写这语句??select * from kczxxb where exists(
    select * from kczxxb a
    where exists(select * from huikb where a.npkh=npkh) )