MySql教程

MySQL 某列数据所占总和百分比 SQL实例

本文主要是介绍MySQL 某列数据所占总和百分比 SQL实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

SELECT a.address,
a.cont AS countAddress,
b.sum AS sumAddress,
CONCAT( ROUND( a.cont / b.sum * 100, 2 ), '', '%' ) AS percent
FROM
( SELECT address, COUNT( address ) AS cont FROM person_base_info GROUP BY address ) a,
(SELECT COUNT(*) AS sum FROM person_base_info ) b

这篇关于MySQL 某列数据所占总和百分比 SQL实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!