Get column sum and use to calculate percent of total (mySQL)

后端 未结 3 1383
眼角桃花
眼角桃花 2020-12-10 04:28

Here is a very basic look at my table. I have columns 1 and 2 and need to generate column 3. Column 3 is simply the total of the Number column for all Nam

3条回答
  •  长情又很酷
    2020-12-10 04:35

    You can get it with a subselect:

    SELECT Name, Number, Number * 100 / (select sum(Number) FROM MYTABLE) AS '% of total'
    FROM mytable
    

提交回复
热议问题