title: oracle rownum invalid identifier
body: <p>I'm trying to get the top 3 max salary of each department however at the end of my code at q.salary i receive the following error: ORA-00904: "Q"."SALARY": invalid identifier</p>
  
  <p>here is my code</p>
  
  <pre><code>with query as (
     select max(salary), department_id 
     from employees 
     group by department_id
  )
  SELECT ROWNUM as RANK, 
         e.last_name, 
         e.salary
  FROM (
     select department_id, salary
     from employees e, 
          query q 
     where e.salary = q.salary
  )
  where rownums &lt;=3
  </code></pre>
  
  <p>Thank you in advance</p>