Dispaly employee records who gets more salary than the average salary in their department?
Find out nth highest salary from emp table
Select distinct (a.Sal) from emp a where &n = (select count (distinct (b.Sal)) from emp b where a.Sal < = b.Sal);for eg:-enter value for n: 2sal---------3700
This will work for only highest salary n=1 but not work for 2nd and rest nth salary...
Did you have tried this?
Code
SELECT * FROM (SELECT employee_id, salary, dense_rank() OVER ( ORDER BY salary DESC) r FROM employees) a WHERE a.r =3 ;
select * from emp a
where salary >(select avg(salary) from emp b where a.dept_no = b.dept_no);