您的位置:首页 > 数据库 > Oracle

oracle显示两个字段相除的结果

2015-11-10 09:28 1051 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle sql