title: Oracle SQL: Alias Column and Sum with group by
body: <p>I have an alias column <code>m</code> and a sum function.  I know I cannot group by <code>m</code> in the top query because the <code>SELECT</code> has not been executed. I have found that I am able to do this query if I remove the <code>m</code> column, but I need this column to appear in the query.</p>
  <p>So I have tried to put a <code>SELECT</code> and <code>FROM(</code> in front of the query.</p>
  <pre><code>select jobno,m,total
  from (
    select j.jobno,
           sum(r.amtfc) total,
           decode(j.consolno,null,j.shpno,j.consolno) m
  from job j,
       jobother jo,
       revenue r,
       fmparty f
  where j.voidby is  null 
   and  j.unid=jo.job_unid 
   and  j.unid=r.job_unid 
    and r.invdocno is null 
    and f.partyid=r.billing_partyid 
  )
  group by jobno, m
  </code></pre>
  <p>but this is giving me back</p>
  <blockquote>
  <p>&quot;ORA-00979: not a GROUP BY expression&quot;</p>
  </blockquote>
  <p>How can I do this correctly?</p>