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
union
select name,count(name) from t2 where type = 2 group by name
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
select * from
(select * from t1 union all select * from t2)a
group by name having count(*)=1
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
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
是不对的,我是要抛弃记录里相同的记录
t1:
g,1
t2:
g,2
那查询不就错了吗
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
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.个数)
group by name
union
select name,count(name) from t2 where not exists (select * from t1 where t1.name=t2.name)
group by name
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.个数)
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
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
这段是什么意思?
select 1 from (select 。