title: DB2 SQL SUM and GROUPING
body: <p>I am having problems with querying and grouping.</p>
  
  <p>I am needing the following output:</p>
  
  <pre><code>officr, cbal, sname  
  ABC, 500.00, TOM JONES  
  ABC, 200.00, SUE JONES  
  ABC TOTAL 700.00  
  
  RAR, 100.10, JOE SMITH  
  RAR, 200.05,  MILES SMITH  
  RAR TOTAL 300.15  
  </code></pre>
  
  <p>SQL below produces the error:</p>
  
  <blockquote>
    <p>[DB2 for i5/OS]SQL0122 - Column SNAME or expression in SELECT list not valid.</p>
  </blockquote>
  
  <pre><code>SELECT
      lnmast.officr,  SUM(LNMAST.CBAL), lnmast.sname
  FROM
      LNMAST
  WHERE LNMAST.RATCOD IN (6,7,8) AND STATUS NOT IN ('2','8')
  group by lnmast.officr
  </code></pre>