title: MYSQL SUM and substract
body: <p>I have the following SQL query.</p>
  
  <pre><code>SELECT    u.username, SUM(p.points) AS points,
            SUM(sp.spPoints) AS spPoints,
            (SUM(sp.spPoints) - SUM(p.points)) AS Puntos_Restantes
  FROM      users as u
  LEFT JOIN points as p ON (u.userid = p.userid)
  LEFT JOIN sppoints AS sp ON (u.userid = sp.userid)
  WHERE     u.userid = '1'
  GROUP BY  u.userid
  </code></pre>
  
  <p>My goal is to SUM 2 fields and then subtract them but when I execute the above query, the second SUM is wrong.<br>
  The tables are like this:    </p>
  
  <pre><code>points: pointId, userId, points    
  sppoints: spPointId, userId, spPoints    
  </code></pre>
  
  <p>In points I have this amount: 25 and in spPoints: 10
  but when I run the query I get :</p>
  
  <pre><code>points  spPoints    Puntos_Restantes
   25       30              5
  </code></pre>
  
  <p>What is going wrong here?</p>