MySQL 计算百分比

SELECT CONCAT(ROUND(t1.total / t2.totalCount * 100,2),'%') AS '类别百分比',t1.`类别名称`,t1.totalrecord

FROM

(SELECT COALESCE (r2.categoryid) '类别名称', count(r2.categoryid) AS totalrecord, sum(r2.amount) AS total FROM pbms.record r2 WHERE r2.categorytype = 1 GROUP BY r2.categoryid) t1,

(SELECT sum(r.amount) AS totalCount FROM pbms.record r WHERE r.categorytype = 1 ) t2

ORDER BY 类别百分比 DESC ;

猜你喜欢

转载自blog.csdn.net/yudiandian2014/article/details/129729999