这篇文章主要介绍MySQL如何求百分率,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
报表业务要求求字段分类在表中百分率,SQL如下(SQL中表为本人业务表,须更改):
Mysql代码
SELECT biz_type,round((sumCate/sumCount)*100,2) as percent
From (select biz_type, count(id) as sumCate from sta_report group by biz_type) as a,
(select count(id) as sumCount from sta_report) as b
结果只需加上“%”即可,已经乘以了“100”,且已经把结果截断为只含二位小数。
附SQL中取小数点后两位语句:
select round(小数,2) from 表
select convert(decimal(18,2),round(小数,2)) from 表
select cast(小数 as numeric(10,2)) from 表
以上是“MySQL如何求百分率”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!