title: How to use sum function in a subquery?
body: <p>I am using a IBM DB2 DBMS and I would like to show the total amount paid per client. Currently when I select all, it will show me multiple pay amounts per clients and this leads to repeating clients.</p>
  
  <p>I would like to show the total amount paid per client, against an arbitrary number that is not in my table. </p>
  
  <p>This is what I have thus far. I am getting an error with my subquery.</p>
  
  <pre><code>SELECT T1.CLIENT_ID 
      (SELECT SUM(T2.PAY_AMT) FROM AR_SUM T2 WHERE T1.CLIENT_ID = T2.CLIENT_ID) AS TOTAL
      FROM AR_SUM T1
      GROUP BY CLIENT_ID
  FETCH FIRST 100 ROWS ONLY
  </code></pre>
  
  <p>I would like it to show:</p>
  
  <pre><code>Client_ID     TOTAL
  abc           100
  def           200
  ghi           150
  </code></pre>
  
  <p>As I mentioned earlier, I would like to compare that to an arbitrary goal amount that is not in my table. Also, is there a way to translate that to a percentage?</p>
  
  <p>My end product I would like:</p>
  
  <pre><code>Client_ID     TOTAL     percent of total &lt;-- (lets say out of 100)
  abc           10        .10 or 10% &lt;-- if possible 
  def           20        .2
  ghi           15        .15
  </code></pre>