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

50分问关于多表查询的问题
有类似下面这样两个表:
1.存储的是月工资和考核分数
userid     monthpay   monthscore

2.存储的是季奖金和考核分数
userid     quarterpay   quarterscore

现在,要把每个员工的工资总和,月平均考核分数,奖金总和,季平均考核分数统计出来

sql语句怎么写?
select   a.userid,sum(a.monthpay),avg(a.monthscore),sum(b.quarterpay),avg(b.quarterscore)   form   ……

------解决方案--------------------
select a.userid,sum(a.monthpay),avg(a.monthscore),sum(b.quarterpay),avg(b.quarterscore) form a,b where a,userid=b.userid
没有试过,不过应该可以 的.
------解决方案--------------------
select *
from (
(select userid, sum(monthpay),avg(monthscore) from TabA group by userid) A
left join
(select userid, sum(quarterpay),avg(quarterscore) form TabB group by userid) B
on A.userid = B.userid
)



------解决方案--------------------
楼上的可以了。楼主可能不太熟悉group by