title: Sums and subtotals in SELECT... HAVING result
body: <p>I'm trying to get the sum of each customer's orders separately, but I'm actually getting the sum of <em>all</em> the orders. What am I doing wrong here?</p>
  
  <pre><code>SELECT c.customerNumber, sum( r.quantityOrdered * r.priceEach ) AS sum
  FROM customers c, orders o, orderdetails r
  WHERE c.customerNumber = o.customerNumber
  AND o.orderNumber = r.orderNUmber
  GROUP BY c.customerNumber
  HAVING COUNT( o.orderNumber ) &lt;=3
  </code></pre>