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 &oracle账号nbsp; 3.7143