当前位置: 代码迷 >> Sql Server >> 查多个雷同结构表中某个字段出现的次数方法
  详细解决方案

查多个雷同结构表中某个字段出现的次数方法

热度:4   发布时间:2016-04-27 11:03:12.0
查多个相同结构表中某个字段出现的次数方法
假如有20个结构相关的表,字段分别为a,b,c,d,e...t,其中b为人员编号,怎样查询20个表中不同人出现的次数(分组统计记录数),有几种方法?

------解决方案--------------------
SQL code
select b,count(1) from (select * from aunion allselect * from bUnion allselect * from c...union allselect * from t) Tgroup by b
------解决方案--------------------
SQL code
select b,count(*) from (select * from 表1union allselect * from 表2Union allselect * from 表3...union allselect * from 表20) tbgroup by b
  相关解决方案