title: Can't do SUM of SUM?
body: <p>The following query seems to have a problem to calculate "ratingValue" because there is SUM(h.liked) inside a SUM.</p>
  
  <pre><code>SELECT d.itemID1 as item, 
      sum(d.sum + d.count*SUM(h.liked))/sum(d.count) as ratingValue
  FROM history h, dev d 
  WHERE h.userID=:id_user
      AND d.itemID1&lt;&gt;h.itemID 
      AND d.itemID2=h.itemID 
  GROUP BY d.itemID1,h.itemID 
  </code></pre>
  
  <p>For a better understanding this is the original and working query (from the Slop One algorithm) :</p>
  
  <p>I just substitute the "rating" table with "history" because in my case r.ratingValue is the sum of all the "like" a user has given to an itemID (=> r.ratingValue = SELECT SUM(liked) FROM history GROUP BY h.itemID ) :</p>
  
  <pre><code>SELECT d.itemID1 as item, 
      sum(d.sum + d.count*r.ratingValue)/sum(d.count) as ratingValue 
  FROM rating r, dev d 
  WHERE r.userID=$userID 
      AND d.itemID1&lt;&gt;r.itemID 
      AND d.itemID2=r.itemID 
  GROUP BY d.itemID1
  </code></pre>