SELECT * FROM ( SELECT employee_id, last_name, salary, RANK() OVER (ORDER BY salary DESC) EMPRANK FROM employees) where emprank > 10 and emprank < 13 -- WHERE emprank = 2;
with cte_emp_dep as ( SELECT emp.first_name, emp.last_name, emp.salary, dep.department_name FROM employees emp left join departments dep on emp.department_id = dep.department_id where salary < 9000 ), cte_sal_bin as ( select cte_emp_dep.*, trunc(salary, -3) sal_bin from cte_emp_dep ), cte_rank as ( select cte_sal_bin.*, dense_rank() over (order by sal_bin) rank_sal_bin from cte_sal_bin ) select * from cte_rank where rank_sal_bin < 10 order by salary