title: MYSQL select maximum sum of purchases
body: <p>I have the following Table named Order</p>
  
  <pre><code>Orders Table
  ___________________________________________________
  orderiD | userId | OrderType | Order_Date | Amount
  ________|________|___________|____________|________
  1          1          0         12/12/2009    1
  2          1          1         13/12/2009    2
  3          1          1         14/12/2009    3
  4          2          0         12/12/2009    4
  5          2          1         16/12/2009    2
  6          1          0         14/12/2009    5
  7          2          1         17/12/2009    4
  8          2          0         10/12/2010    2
  ___________________________________________________
  </code></pre>
  
  <p>I need to create query which returns user id with maximum SUM of purchases. </p>
  
  <p>I tried the following</p>
  
  <pre><code>Select MAX(GRP.sumAmmount), o.userId join
  (Select SUM(o.Amount) as sum_ammount, o.userId as UID from Orders GROUP BY(o.userID)) as GRP on o.userId=GRP.UID GROUP BY(GRP.UID)
  </code></pre>
  
  <p>But I believe I'm missing something.</p>
  
  <p>Can you help?</p>