title: MySQL comparing total sums to all sums in expenses, income, savings (3 different tables) as percentage per month
body: <p>I'm trying to create a query which allows me to get a percentage value for each month comparing expenses, incomes and savings whith each other. I'm using MySQL database.</p>
  
  <p>Example to the tables and the query:
  <a href="http://sqlfiddle.com/#!9/78b360/1" rel="nofollow noreferrer">http://sqlfiddle.com/#!9/78b360/1</a></p>
  
  <p>So far I'm able to get the SUM per month from each table:</p>
  
  <pre><code>SELECT *
  FROM(
  SELECT sum(amount) AS Total, month(date) AS Month FROM expenses
  UNION ALL
  SELECT sum(amount), month(date) FROM income
  UNION ALL
  SELECT sum(amount), month(date) FROM savings
  GROUP BY month(date)) as grand_total
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>|   Total | Month |
  |---------|-------|
  | 1323232 |     9 |
  |  300101 |     9 |
  |   20000 |     9 |
  |       1 |    10 |
  </code></pre>
  
  <p>what I'm trying to achieve is something like this if I only look at month 9 :</p>
  
  <pre><code>|   Total | Month | Percent
  |---------|-------|--------
  | 1323232 |     9 |     81%
  |  300101 |     9 |     18%
  |   20000 |     9 |      1%
  </code></pre>
  
  <p>Can you please help me out here? I have looked at many-many answers on stackoverflow and other sites but could not find what I exactly needed. Your help is much appreciated. Thank you. </p>