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

You just need to CROSS JOIN the SUM() of Number column:

SELECT Name, Number, Number * 100 / t.s AS `% of total`
FROM mytable
CROSS JOIN (SELECT SUM(Number) AS s FROM mytable) t

Demo Here

Leave a Comment