報表業務要求求字段分類在表中百分率,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 表
作者“憤怒的三米”