title: ROW_NUMBER() in DB2
body: <p>How to use ROW_NUMBER() in where clause in DB2 database.
   I have tried below but it did not work:</p>
  
  <pre><code>SELECT * FROM CSPAPP.LOCATIONS
  WHERE (ROW_NUMBER() OVER(ORDER BY LOCATION)) BETWEEN 100 AND 200
  </code></pre>
  
  <p>It gave error : Invalid use of aggregate function or OLAP function.</p>
  
  <p>I also tried with followiong ways :</p>
  
  <pre><code>SELECT (ROW_NUMBER() OVER(ORDER BY LOCATION)) AS RN ,* FROM CSPAPP.LOCATIONS
  WHERE RN &lt; 200
  
  SELECT (ROW_NUMBER() OVER(ORDER BY LOCATION)) AS RN ,LOCATION FROM CSPAPP.LOCATIONS
  WHERE RN &lt; 200
  </code></pre>