Hi All,
I have following problem to be solved. I have a table with following structure:
Table emp
EmpID number
NAme varchar2
DeptID number
Salary number
Now for finding max salary in each dept, I can use:
select DeptId,max(salary) from emp group by DeptId;
NOw to find second max salary, I can do below:
select DeptId,max(salary) from emp
where (DeptId,salary) not in (select DeptId,max(salary) salary from emp group by DeptId) group by DeptId;
But suppose I need to find 5th or 6th max salary then this method will be cumbersome.
I need a
SQL query in which I can dynamically pass the parameter to calculate it.
Kindly help.