gpt4 book ai didi

mysql 百分比 2 位小数

转载 作者:行者123 更新时间:2023-11-29 05:51:18 25 4
gpt4 key购买 nike

使用以下 MYSQL 代码,我试图将我的百分比四舍五入到小数点后两位,我尝试了截断和四舍五入但是当我从我的输出中添加所有百分比时我没有得到 100% 得到像 99.9%、99.95 这样的数字%等

请查看我更新的完整查询,以显示每种类型的计数、未四舍五入的百分比和四舍五入的百分比:

select
bondtype,
count(distinct secid) AS Count,
concat(count(distinct secid)/(select count(distinct secid) from wca.bond)*100, '%') as Percentage,
concat(ROUND(count(distinct secid)/(select count(distinct secid) from wca.bond)*100, 2), '%') as Percentage_with_Rounding
from wca.bond
group by bondtype;

以下是我得到的输出:

enter image description here

请注意,对于 bondtype CS,Percentage_with_Rounding 应该是 0.05% 而不是 0.04%,所有其他计数在四舍五入后看起来都是正确的,但只有这个我觉得很奇怪。提前致谢

最佳答案

像这样选择 cast(round(((1*100.0)/9),2) as decimal(5,2))

选择安全类型,ROUND(truncate(concat(count(distinct secid)/(select count(distinct secid) from securities)*100.0), 2)) 作为百分比来自 wca.bond按安全类型分组;

关于mysql 百分比 2 位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53902161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com