title: How do I select the max value after a SUM() + Group By?
body: <p>I have an SQL final exam in college in a few days and I have a query that's driving me crazy! I know it's a dumb query, but I'm just getting started and can't figure it out.</p>
  <p>So, there's basicaly 2 tables, Client and Orders.</p>
  <pre><code>     Client           Orders
       ---------        ---------
   PK  Client_Id    PK  Order_Id
       Name             Client_Id   FK
                        Order_Total
                        Date
  </code></pre>
  <p>Now, they ask me to <em>&quot;List the name of the client that bought the most in 2011&quot;</em></p>
  <p>So, for what I thought, this requires on one side, that I SUM all the Order_Total and Group by Client from 2011, then from that table, select the client with the MAX() sum of order totals, and then show only the name of that client. The problem is that I can't figure how to put all that in one query.</p>
  <p>Hope somebody can help!</p>
  <hr />
  <p>Thank you all for your very quick responses! I'm really impressed!</p>
  <p>Now, I don't mean to be picky or anything, but just in case my teacher doesn't accept the &quot;Limit&quot; or &quot;Select top&quot; statement, is there any way to do this query without those?</p>
  <h3>Edit: Original code attempt ported from comments:</h3>
  <pre><code>SELECT 
    C.NAME
  FROM 
    CLIENTS C,
    ORDERS O 
  WHERE 
    O.CLIENT_ID = C.CLIENT_ID 
    AND O.DATE BETWEEN '1/1/2011 00:00:00.000' and '12/31/2011 23:59:59.999' 
  HAVING SUM(O.ORDER_TOTAL) &gt;= ALL (SELECT SUM (O2.ORDER_TOTAL) FROM ORDER O2 GROUP BY O2.CLIENT_ID)
  </code></pre>