title: Finding the MIN value from the SUM of multiple row grouped by some id
body: <p>I am using SQLplus connecting to oracle database 12c</p>
  
  <p>I have two tables, Customer and Account, where customers can have multiple accounts (one customer id, but multiple account types). I am trying to get the information on the customer with the largest amount of debt. Suppose we have the following information:</p>
  
  <p>Customer table:</p>
  
  <pre><code>BSB#  Customer#  Name  Address
  ------------------------------
  0123  123456     Adam  ABC st
  0234  234566     Dave  CBC rd
  0345  345667     Max   DSE st
  </code></pre>
  
  <p>Account table:</p>
  
  <pre><code>BSB#  Customer#  Type    Balance
  ---------------------------------
  0123  123456     Saving  -2300
  0123  123456     Credit  -500
  0123  123456     iSaver  200
  0234  234566     Saving  5000
  0345  345667     Credit  -1500
  0345  345667     iSaver  -200
  </code></pre>
  
  <p>The desired output:</p>
  
  <pre><code>Customer# Name   Address
  -------------------------
  123456    Adam   ABC St
  </code></pre>
  
  <p>I can print out the sum of everyone's account balance, but I am not sure how to print out just the information on the account with the lowest accumulated balance. I tried using MIN(SUM(A.Balance)) but I keep getting the error saying "not a single-group function". I wouldn't be surprised if I made a mistake somewhere.</p>
  
  <p>I am relatively new to sql and this is what I have so far. Any advice or pointers would be nice...</p>
  
  <pre><code>SELECT C.Customer#, C.Name, Address, SUM(A.Balance)
  FROM Customer C
  RIGHT OUTER JOIN Account A
  ON C.BSB# = A.BSB#
  AND
  C.Customer# = A.Customer#
  GROUP BY C.Customer#, C.Name, Address;
  </code></pre>
  
  <p>Thanks!</p>