title: How do I subtract two declared variables in MYSQL
body: <p>The question I am working on is as follows:</p>
  
  <p>What is the difference in the amount received for each month of 2004 compared to 2003?</p>
  
  <p>This is what I have so far,</p>
  
  <pre><code>    SELECT @2003 = (SELECT sum(amount) FROM Payments, Orders
                  WHERE YEAR(orderDate) = 2003
                  AND Payments.customerNumber = Orders.customerNumber
                      GROUP BY MONTH(orderDate));
  
      SELECT @2004 = (SELECT sum(amount) FROM Payments, Orders
                  WHERE YEAR(orderDate) = 2004
                  AND Payments.customerNumber = Orders.customerNumber
                      GROUP BY MONTH(orderDate));
  
      SELECT MONTH(orderDate), (@2004 - @2003) AS Diff 
             FROM Payments, Orders
                WHERE Orders.customerNumber = Payments.customerNumber
                   Group By MONTH(orderDate);
  </code></pre>
  
  <p>In the output I am getting the months but for Diff I am getting NULL please help. Thanks</p>