Skip to content

Instantly share code, notes, and snippets.

@mattm
Created April 24, 2017 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattm/817f272c8390f9995e9e27542d80853a to your computer and use it in GitHub Desktop.
Save mattm/817f272c8390f9995e9e27542d80853a to your computer and use it in GitHub Desktop.
Comma JOIN
SELECT id, amount, ROUND(amount / total * 100) AS percent
FROM charges, (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