title: How to use GROUP BY clause on a derived table in oracle
body: <p>I'm working on a complicated sql query and I always get oracle error ORA-00933 when executing it. I minimized the query to this minimal example:</p>
  
  <pre><code>SELECT foo.bar, sum(foo.baz) 
    FROM (SELECT  123  as bar,  5 as baz FROM dual) as foo
  GROUP BY foo.bar
  </code></pre>
  
  <p>It seems to have to do with using the derived table and the GROUP BY clause.</p>
  
  <p>How do I rewrite the query to support the GROUP BY clause on the derived table <code>foo</code>?</p>