title: MySQL Add and subtract based on Alias value
body: <p>I have a query calculating <code>SUM()</code> based on enum value IN/OUT (see below)</p>
  
  <p><a href="https://i.stack.imgur.com/cUxKz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cUxKz.jpg" alt="enter image description here"></a></p>
  
  <p>I'm trying to extend the calculation and add a second <code>SELECT</code> based on the 
  <code>TOTAL IN</code> and <code>TOTAL OUT</code> outputs using this formula:</p>
  
  <blockquote>
    <p><strong><em>BUDGET + TOTAL IN - TOTAL OUT = TOTAL PROFIT</em></strong> </p>
  </blockquote>
  
  <p>The problem is that the output is wrong (see below)</p>
  
  <p><a href="https://i.stack.imgur.com/JSiMl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JSiMl.jpg" alt="enter image description here"></a></p>
  
  <p>It should be <code>£17,408.90</code></p>
  
  <p>The query I'm trying to extend is:</p>
  
  <pre><code>SELECT
    f.id_festival AS ID,
    CONCAT('£ ', FORMAT(f.festival_budget, 2)) AS Budget,
    CONCAT('£ ', ROUND(SUM(CASE WHEN p.pmt_type = 'Payment IN' THEN p.pmt_amount ELSE 0 END), 2)) AS `TOTAL IN`,
    CONCAT('£ ', ROUND(SUM(CASE WHEN p.pmt_type = 'Payment OUT' THEN p.pmt_amount ELSE 0 END), 2)) AS `TOTAL OUT`,
    (SELECT
        CONCAT('£ ', ROUND(SUM(f.festival_budget + 'TOTAL IN') - 'TOTAL OUT', 2))) AS PROFIT
  FROM festival f
    INNER JOIN payment p
      ON p.id_festival = f.id_festival
  WHERE f.id_festival = 1
  GROUP BY f.id_festival
  </code></pre>
  
  <p>I can't figure out where that 115.000 came from. 
  Any help will be appreciated. </p>