Created
April 24, 2017 00:59
-
-
Save mattm/1cdc583733f3c94f1baa4bb1efe31fca to your computer and use it in GitHub Desktop.
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
SELECT id, amount, ROUND(amount / total * 100) AS percent | |
FROM charges | |
INNER JOIN (SELECT SUM(amount) AS total FROM charges) t; | |
+----+--------+---------+ | |
| 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