您好,欢迎来到凌优教育。
搜索
您的当前位置:首页MySQL求百分率_MySQL

MySQL求百分率_MySQL

来源:凌优教育


bitsCN.com

报表业务要求求字段分类在表中百分率,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 表

作者“愤怒的三米”

bitsCN.com

Copyright © 2019- linuxxuexi.com 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务