统计所有返回码是00的记录,计算成功率。
select round(sum(case when resp_code='00'then 1 else 0 end)/count(*)*100,2)||'%' as rate from tbl_txn
oracle 中的round函数:round(数值,保留小数点位数)
计算带有一定条件的成功率,一般我们做报表的时候都会加上种种查询条件,比如机构,时间之类的。
select round(sum(case when resp_code='00'then 1 else 0 end)/count(*)*100,2)||'%' as rate from (select 查询的语句)
计算比率,并计算平均值,因为每一天是一条记录,所以没有需要加权的地方,所以语句如下:
select t.brno,t.terminal_code,t.txn_date, round((t.open_cnt/(24*60))*100,2)||'%' rate,t1.average_rate from tbl_atm_scan t,(select t.terminal_code,round(sum(t.open_cnt)/(24*60*count(*))*100,2)||'%' average_rate from tbl_atm_scan t group by t.terminal_code) t1 where t1.terminal_code=t.terminal_code order by t.brno
本文介绍如何使用SQL来计算特定条件下操作的成功率和比率。通过示例展示了如何针对不同的业务需求构建查询语句,包括计算特定返回码的成功率以及计算并展示每日的开放比率平均值。
326

被折叠的 条评论
为什么被折叠?



