Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Charges with Subquery
SELECT *, ROUND(amount / (SELECT SUM(amount) FROM charges) * 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
You can’t perform that action at this time.