首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mysql percentage 2位小数

mysql percentage 2位小数
EN

Stack Overflow用户
提问于 2018-12-23 16:14:47
回答 1查看 1.8K关注 0票数 1

使用下面的MYSQL代码,我尝试将百分比四舍五入到小数点后两位,我尝试了截断和四舍五入,但当我将输出中的所有百分比相加时,我得不到100%,比如99.9%、99.95%等数字

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

代码语言:javascript
复制
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%,所有其他计数在舍入后看起来都是正确的,但只有这一个我觉得奇怪。提前感谢

EN

回答 1

Stack Overflow用户

发布于 2018-12-23 16:30:24

select _secid_ from,ROUND(truncate(concat(count(distinct _ secid) from securities)*100.0),2))按secid_from从wca.bond组中取百分比;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53902161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档