用户表--- user
uid username
1 user1
2 user2
3 user3
.........
数据表1--- table1
id useranme a b c d
1 user1 1 1 1 1
2 user1 1 1 1 1
3 user2 1 1 1 1
4 user3 1 1 1 1
5 user2 1 1 1 1
6 user3 1 1 1 1
数据表2 ----table2
id username suma sumb sumc sumd
select username,suma=sum(a),sumb=sum(b),subc=sum(c),subd=sum(d) from table1 aa
where exists( select * from user1 where username=aa.username)
group by username
select u.username,suma=sum(a),sumb=sum(b),subc=sum(c),subd=sum(d)
from ((select * from user1) as u inner join table1 on u.username=table1.username)
group by u.username