title: Alternative to GROUP BY
body: <p>I have the table with <code>billID</code> being the primary key:</p>
  
  <p><code>Invoice (billID, item, value, quantity)</code></p>
  
  <p>and the following query:</p>
  
  <pre><code>SELECT item, sum(quantity) AS TotalItems
  FROM Invoice
  WHERE value&gt;1
  GROUP BY item
  HAVING sum(quantity)&gt;10
  </code></pre>
  
  <p>I need to rewrite to <em>optimize</em> (or <em>de-optimize</em>?) using only <code>SELECT</code>, <code>FROM</code> and <code>WHERE</code>. </p>
  
  <ol>
  <li>What is the new query eliminating <code>GROUP BY</code> and <code>HAVING</code>?</li>
  <li>Is it always possible to eliminate <code>GROUP BY</code> &amp; <code>HAVING</code> and use only <code>SELECT</code>, <code>FROM</code> and <code>WHERE</code>?</li>
  </ol>
  
  <p><strong>My approach:</strong></p>
  
  <p>[1] I am using <code>UNION</code> of different <code>items</code> to achieve this. But the major problem is that I need to know all the <code>item</code> before hand. </p>
  
  <pre><code>SELECT item, sum(quantity) FROM Invoice WHERE item='lumia'
  UNION
  SELECT item, sum(quantity) FROM Invoice WHERE item='iphone'
  UNION
  SELECT item, sum(quantity) FROM Invoice WHERE item='samsung'
  UNION
  SELECT item, sum(quantity) FROM Invoice WHERE item='moto'
  .
  .
  .
  and so on
  </code></pre>
  
  <p>Is there another way to get the result?</p>