当前位置: 代码迷 >> Sql Server >> 从多个构造相同的表中统计数据
  详细解决方案

从多个构造相同的表中统计数据

热度:47   发布时间:2016-04-25 01:13:55.0
从多个结构相同的表中统计数据
表:
bbsrep1 , bbsrep2, bbsrep3,bbsrep4 …… bbsrep7 结构相同,数据不同

现在要统计 username 是 'kaka' 的用户数据。

sql语句怎么写?

单个表:
select count(id) from bbsrep1 where username = 'kaka' 

7个表联合起来怎么查?

------解决方案--------------------
SQL code
--或者select count(id) from (select id,username from bbsrep1union allselect id,username from bbsrep2union allselect id,username from bbsrep3union all...) a where username ='kaka'