1:统计在“TJ”和“HIST”两表中有多少{数据是相同的}select count(*) from tj m, hist n where m.part1 = n.part1 and m.part2 = n.part2 and m.part3 = n.part3
2,3,4看不懂,貌似乎逻辑不对.

解决方案 »

  1.   

    1.
    select a.*
    from TJ a
    where exists(select 1 from HIST b where a.part1=b.part1 and a.part2=b.part2 and a.part3=b.part3 )
    2.
    select a.*
    from TJ a
    where exists(select 1 from HIST b where a.part1=b.part1 and a.part2=b.part2 and a.part3<>b.part3 )3.
    select a.*
    from TJ a
    where not exists(select b.part2 from HIST b where a.part1=b.part1 )4.
    select a.*
    from HIST a
    where not exists(select b.part2 from TJ b where a.part1=b.part1 )
      

  2.   

    先谢了
    是这样的,我要用VB编写一个程序,但需用到SQL,并用SQL实现对两个表指定字段的内容进行比较,类似如:
    select part1,part2,part3 from TJ where ... “比较函数或其他”...(select part1,part2,part3 where part1='aaa' and ...)
    主要是比较字段对应的数据,按照上面不同的需求对select的结果count,以后做一个百分比统计。不知我描述的清不清楚,本人能力有限,还请各位高手多指教
      

  3.   

    多谢dawugui &  hdhai9451 两位热心高手帮助!
    我已经测试过,exists的确不错,我用过minus 但感觉不太适合我的需求(也许我水平有限),呵呵!
    非常感谢!结帖!