A表:
姓名   成绩   性别
一      10    男
二      20    女
三      15    男
表B
姓名   成绩   性别
一      10    男
二      20    女
三      15    男
四      20    女
八      20    女
我的问题是:比对2张表,从中挑出不一样的数据,并产生一张新表!谢谢!

解决方案 »

  1.   

    select *
    from tb b 
    where not exists(select 1 from ta where checksum(姓名,成绩, 性别) = checksum(b.姓名,b.成绩, b.性别)
      

  2.   

    --前提:表中不能有text、ntext、image、cursor 数据类型的字段。用CheckSum()最简单:select * into newtb from
    (
    select * from A where checksum(*) not in (select checksum(*) from B)
    union all
    select * from B where checksum(*) not in (select checksum(*) from A)
    ) t
      

  3.   


    select [姓名] ,[成绩] ,[性别] 
    from 
    (
    select * from  a union all select * from b
    ) v
    group by [姓名] ,[成绩] ,[性别] 
    having count(1)=1
      

  4.   

    select *
    from tb b 
    where not exists(select 1 from ta where checksum(姓名,成绩, 性别) = checksum(b.姓名,b.成绩, b.性别)
      

  5.   

    select coalesce(a.姓名,b.姓名) 姓名,
     coalesce(a.成绩,b.成绩) 成绩,
     coalesce(a.性别,b.性别) 性别
    from a full join b 
    on checksum(a.姓名,a.成绩,a.性别) = checksum(b.姓名,b.成绩, b.性别)
      

  6.   

    select * from #A except select * from #B
    union all
    select * from #B except select * from #A
      

  7.   

    对比2张表中姓名不一样的数据,该怎么做啊?还有from tb b和select 1 from ta 是什么意思啊?感激不尽!
      

  8.   

    select a.* from a except select b.* from b /*找出a表中有的数据b表中没有的数据*/
    union all
    select b.* from b except select a.* from a /*找出b表中有的数据a表中没有的数据*/
      

  9.   

    select A.姓名, A.成绩, A.性别
    into C
    from A, B
    where A.姓名 <> B.姓名 and A.成绩 = B.成绩 and A.性别 = B.性别
      

  10.   


    create table A(
        姓名  nvarchar(5)
        ,成绩 int
        ,性别 nvarchar(1)
    )
    goinsert into A
    select '一',10,'男' union all
    select '二',20,'女' union all
    select '三',15,'男'
    gocreate table B(
        姓名  nvarchar(5)
        ,成绩 int
        ,性别 nvarchar(1)
    )
    goinsert into B
    select '一',10,'男' union all
    select '二',20,'女' union all
    select '三',20,'男' union all
    select '四',20,'女' union all
    select '八',20,'女'
    goselect 'A中有而B中没有的姓名', A.* from A left join B on a.姓名 = b.姓名 where b.姓名 is null
    union all
    select 'B中有而A中没有的姓名', B.* from B left join A on a.姓名 = b.姓名 where a.姓名 is null
      

  11.   

    select 姓名 ,成绩 ,性别
    from
    (
    select * from A union all select * from B
    ) v
    group by 姓名,成绩,性别
    having count(1)=1
      

  12.   

    (select #B.* from #B except select #A.* from #A ) 
    union all
    (select #A.* from #A except select #B.* from #B )
      

  13.   

    从中挑出不一样的数据,并产生一张新表select *
    into newtable
    from (
    select * from a
    union
    select * from b) as a
      

  14.   

    select *
    from tb b 
    where not exists(select 1 from ta where checksum(姓名,成绩, 性别) = checksum(b.姓名,b.成绩, b.性别)