Calculation of percentage of group count(*)

前端 未结 4 747
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 02:58
Select * from Namelist;
Name      Age
Sathish   25
Sathish   65
Sathish   55
Sathish   45
Sathish   35
Jana      55
Jana      25
Jana      10
Bala      55
Bala               


        
4条回答
  •  太阳男子
    2021-01-01 03:42

    replace column name and try this:

    SELECT  iName, 
        COUNT(iName) AS `Count`, 
        concat(FORMAT(((COUNT(iName) * 100) / NewPeople.iCount),2),'%') AS `Percentage`
    FROM   people, (SELECT COUNT(iName) AS iCount FROM people) NewPeople 
    GROUP BY iName;
    

    Output:

    Name   Count   Percentage
    Sathish  5     50.00%
    Jana     3     30.00%
    Bala     2     20.00%
    

提交回复
热议问题