select sum(a.pf_value) totalrating ,count(zy_id) countrating from mic_td_user_pf a
where a.zy_id=199 and a.pf_type=2
显示结果为
totalrating countrating
26 7
select b.countrating ,b.totalrating/b.countrating avgrating from (select sum(a.pf_value) totalrating ,count(zy_id) countrating from mic_td_user_pf a
where a.zy_id=199 and a.pf_type=2) b
countrating avgrating
7 3.71428571428571
保留4位小数
select b.countrating ,round(b.totalrating/b.countrating,4) avgrating
from (select sum(a.pf_value) totalrating ,count(zy_id) countrating
from mic_td_user_pf a where a.zy_id=199 and a.pf_type=2 and a.del_mark = 0) b ;
countrating avgrating
7 3.7143