欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle数据库显示两个字段相除的结果分析

程序员文章站 2022-03-08 23:05:22
select sum(a.pf_value) totalrating ,count(zy_id) countrating from mic_td_user_pf a   where a.z...

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