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

从多个结构相同的表中统计数据
表:
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 bbsrep1
union all
select id,username from bbsrep2
union all
select id,username from bbsrep3
union all
...) a where username ='kaka'