Last active
April 23, 2017 18:36
-
-
Save mattm/63b9a55c1f7f122e921472628d6c9f30 to your computer and use it in GitHub Desktop.
Charges with Varible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @total := (SELECT SUM(amount) FROM charges); | |
SELECT *, ROUND(amount / @total * 100) AS percent | |
FROM charges; | |
+----+--------+---------+ | |
| id | amount | percent | | |
+----+--------+---------+ | |
| 1 | 18.00 | 30 | | |
| 2 | 15.00 | 25 | | |
| 3 | 27.00 | 45 | | |
+----+--------+---------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment