select name,count(name) from t1 where type = 1 group by name
union 
select name,count(name) from t2 where type = 2 group by name

解决方案 »

  1.   

    1.
    select a=sum(case when name='a' then 1 else 0 end),
        b=sum(case when name='b' then 1 else 0 end),
        c=sum(case when name='c' then 1 else 0 end)
    from t1 group by name2.select a=sum(case when name='a' then 1 else 0 end),
        b=sum(case when name='b' then 1 else 0 end),
        d=sum(case when name='d' then 1 else 0 end)
    from t2 group by name
      

  2.   

    3.
    select * from 
    (select * from t1 union all select * from t2)a
    group by name having count(*)=1
      

  3.   

    select isnull(a.name,b.name) as name,isnull(a.counts,b.counts) as counts
    from (select name,count(*) as counts from t1 group by name) a
    full join
    (select name,count(*) as counts from t2 group by name ) b on a.name=b.name and a.counts=b.counts
    where a.name is null or b.name is null
      

  4.   


    select a.namea.type from 
    (select name,count(name) from t1 where type = 1 group by name
     union all
     select name,count(name) from t2 where type = 2 group by name) a
    group by a.name having count(*)=1
      

  5.   

    having count(*)=1
    是不对的,我是要抛弃记录里相同的记录
    t1:
    g,1
    t2:
    g,2
    那查询不就错了吗
      

  6.   

    或者数据是这样也不对了。
    t1:name,type
    a,1
    b,1
    a,1
    b,1
    c,1
    a,1t2:name,type
    a,2
    b,2
    a,2
    b,2
    d,2
      

  7.   

    select a.* from (select name,count(name) as 个数 from t1 where type = 1 group by name) a where not exists(select 1 from (select name,count(name)  as 个数 from t2 where type = 2 group by name) b where a.name=b.name and a.个数=b.个数)
    union 
    select b.* from (select name,count(name) as 个数 from t2 where type = 2 group by name) b where not exists(select 1 from (select name,count(name)  as 个数 from t1 where type = 1 group by name) b where a.name=b.name and a.个数=b.个数)
      

  8.   

    select name,count(name) from t1 where not exists (select * from t2 where t1.name=t2.name)
      group by name
    union 
    select name,count(name) from t2 where not exists (select * from t1 where t1.name=t2.name)
      group by name
      

  9.   

    try:
    select a.* from (select name,count(name) as 个数 from t1 where type = 1 group by name) a where not exists(select 1 from (select name,count(name)  as 个数 from t2 where type = 2 group by name) b where a.name=b.name and a.个数=b.个数)
    union 
    select b.* from (select name,count(name) as 个数 from t2 where type = 2 group by name) b where not exists(select 1 from (select name,count(name)  as 个数 from t1 where type = 1 group by name) a where b.name=a.name and b.个数=a.个数)
      

  10.   

    select b.name,b.counts 
    from (select a.t,a.name,count(*) as counts
          from (select t=1,* from t1 union all select t=2,* from t2) a
          where (select count(*) from t1 where name=a.name)<>
                (select count(*) from t2 where name=a.name)
          group by a.name ) b
      

  11.   

    改一下
    select b.name,b.counts 
    from (select a.t,a.name,count(*) as counts
          from (select t=1,* from t1 union all select t=2,* from t2) a
          where (select count(*) from t1 where name=a.name)<>
                (select count(*) from t2 where name=a.name)
          group by a.t,a.name ) b
      

  12.   

    sdhdy(大江东去...)谢谢了!  
    这段是什么意思?
    select 1 from (select 。