使用下面的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;下面是我得到的输出:

注意,键合类型CS的Percentage_with_Rounding应该是0.05%,而不是0.04%,所有其他计数在舍入后看起来都是正确的,但只有这一个我觉得奇怪。提前感谢
发布于 2018-12-23 16:30:24
select _secid_ from,ROUND(truncate(concat(count(distinct _ secid) from securities)*100.0),2))按secid_from从wca.bond组中取百分比;
https://stackoverflow.com/questions/53902161
复制相似问题