title: Using rownum in subquery
body: <p>In an algorithm the users passes a query, for instance:</p>
  
  <pre><code>SELECT o_orderdate, o_orderpriority FROM h_orders WHERE rownum &lt;= 5
  </code></pre>
  
  <p>The query returns the following:</p>
  
  <pre><code>1996-01-02  5-LOW
  1996-12-01  1-URGENT
  1993-10-14  5-LOW
  1995-10-11  5-LOW
  1994-07-30  5-LOW
  </code></pre>
  
  <p>The algorithm needs the count for the select attributes (<code>o_orderdate, o_orderpriority</code> in the above example) and therefore it rewrites the query to:</p>
  
  <pre><code>SELECT o_orderdate, count(o_orderdate) FROM 
    (SELECT o_orderdate, o_orderpriority FROM h_orders WHERE rownum &lt;= 5) 
  GROUP BY o_orderdate
  </code></pre>
  
  <p>This query returns the following:</p>
  
  <pre><code>1992-01-01  5
  </code></pre>
  
  <p>However the intended result is:</p>
  
  <pre><code>1996-12-01  1
  1995-10-11  1
  1994-07-30  1
  1996-01-02  1
  1993-10-14  1
  </code></pre>
  
  <p>Any idea how I could rewrite the parsing stage or how the user could pass a syntactically different query to receive the above results?</p>