select age,sum(no) as sno from ( select age,count(1) as no from T1 uinon select age,count(1) as no from T2)T group by age
select sum(id),age from ( select * from T1 union select * from T2) as a group by age
select 'group1' as groupName,COUNT(*) as groupCount from t1 where exists (select 1 from t2 where t1.age=t2.age) union select 'group2',SUM(group2) from ( select COUNT(*) as group2 from t1 where not exists (select 1 from t2 where t1.age=t2.age) union select COUNT(*) as group2 from t2 where not exists (select 1 from t1 where t1.age=t2.age) )t
稍加一下改动select T.age,sum(no) as sno from ( select t2.age,count(t2.age) as no from Table2 t2 group by t2.age union select t3.age,count(t3.age) as no from Table3 t3 group by t3.age )T group by T.age
from (
select age,count(1) as no
from T1
uinon
select age,count(1) as no
from T2)T
group by age
select sum(id),age
from (
select * from T1
union
select * from T2) as a
group by age
from t1 where exists (select 1 from t2 where t1.age=t2.age)
union
select 'group2',SUM(group2)
from (
select COUNT(*) as group2 from t1 where not exists (select 1 from t2 where t1.age=t2.age)
union select COUNT(*) as group2 from t2 where not exists (select 1 from t1 where t1.age=t2.age)
)t
稍加一下改动select T.age,sum(no) as sno
from
( select t2.age,count(t2.age) as no from Table2 t2
group by t2.age
union
select t3.age,count(t3.age) as no from Table3 t3
group by t3.age
)T
group by T.age