>  기사  >  데이터 베이스  >  MySQL求百分率_MySQL

MySQL求百分率_MySQL

WBOY
WBOY원래의
2016-06-01 13:44:521138검색

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
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.