两个sql表,sdf在fsdf数据库中,gzk在gzgl数据库中
sdf的结构为
gh          lsf
600001      10.00
600002      12.00gzk的结构为:
gh            lsf
600001       10.00 
 
我曾经利用gh做索引把sdf的数据导入到gzk中,但是现在两个表的lsf总数不一致,可能是gh设置有错误,
我现在想找出gzk中gh在sdf中有,lsf=0的记录,既找出应该导入却没有数据的记录,这条查询语句我该怎么写?

解决方案 »

  1.   

    ?
    select * from gzk where gh in(select gh from sdf where lsf=0)
      

  2.   


    select gzk.* from gzk,sdf where gzk.gh=sdf.gh and gzk.lsf=0--orselect gzk.* from gzk,sdf where gzk.gh=sdf.gh and sdf.lsf=0
      

  3.   


    select * from gzk where lsf=0 and gh in(select gh from sdf)
    --or
    select gzk.* from gzk,sdf where gzk.gh=sdf.gh and gzk.lsf=0
      

  4.   

    lsf=0 不行
    条件得改改。需要是两个表的lsf不相等
      

  5.   

    select * from sdf t whre exists( select 1 from gzk where gh=t.th and isnull(lsf,1)<>isnull(t.lsf,0))
    select * from gzk t whre exists( select 1 from sdf where gh=t.th and isnull(lsf,1)<>isnull(t.lsf,0))
      

  6.   

    select * from sdf t whre exists( select 1 from gzk where gh=t.gh and isnull(lsf,1)<>isnull(t.lsf,0))
    select * from gzk t whre exists( select 1 from sdf where gh=t.gh and isnull(lsf,1)<>isnull(t.lsf,0))
      

  7.   

    select * from (gh in (select gh from sdf)) and lsf=0