日期:2014-05-17  浏览次数:20397 次

查多个相同结构表中某个字段出现的次数方法
假如有20个结构相关的表,字段分别为a,b,c,d,e...t,其中b为人员编号,怎样查询20个表中不同人出现的次数(分组统计记录数),有几种方法?

------解决方案--------------------
SQL code
select b,count(1) from (select * from a
union all
select * from b
Union all
select * from c
.
.
.
union all
select * from t) T
group by b

------解决方案--------------------
SQL code
select b,count(*) from 
(
select * from 表1
union all
select * from 表2
Union all
select * from 表3
.
.
.
union all
select * from 表20
) tb
group by b