今天为晨检脚本增加了记录记账成功率的功能,SQL 的写法大致为:
select sum(case when 记账状态='记账成功' then 1 else 0 end)/cast(count(1) as decimal(18,2)) from 表 where 条件
这里有两个关键点: