字段A与字段B之间的百分比
select tab.*,decode(tab.A, '0', '0', to_char(round((tab.B / tab.A) * 100, 2) || '%')) as contract_rate
from (select (select 1000 as A from dual) as A, (select 555 from dual) as B
from dual) tab
where 1 = 1

本文介绍了一种使用SQL查询来计算两个字段之间比率的方法。通过DECODE和TO_CHAR函数结合使用,可以实现对特定条件下的数值进行百分比转换,并展示了一个具体的例子。
字段A与字段B之间的百分比
select tab.*,decode(tab.A, '0', '0', to_char(round((tab.B / tab.A) * 100, 2) || '%')) as contract_rate
from (select (select 1000 as A from dual) as A, (select 555 from dual) as B
from dual) tab
where 1 = 1

2万+
4686
5472

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