复杂查询 平均求和
mysql 复杂查询 (对同一字段-做平均(avg) 再做和(sum))
---------------------------------
|user|class|score|
|a1 |en |5 |
|a1 |en |6 |
|a1 |chinese|9 |
|a1 |chinese|7 |
|a2-a100.....
a1的总成绩是(5+6)/2 + (9+7)/2 = 13.500
------解决方案--------------------试试
select a1,avg(score) from (select a1,en,sum(score) as score from table1 group by a1,en) a group by a1
------解决方案--------------------a1的总成绩是(5+6)/2 + (9+7)/2 = 13.500
这和直接计算:a1=(5+6+9+7)/2=13.5有什么区别?!