i need department wise top 2 employees salary.which logic
i will use

Answer Posted / ashok kumar y

SELECT a.deptno, a.sal
FROM (SELECT deptno, sal,
DENSE_RANK () OVER (PARTITION BY deptno ORDER BY sal DESC NULLS LAST) max_sal
FROM emp
WHERE deptno IS NOT NULL) a
WHERE max_sal <= 2 group by deptno,sal ;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is faster subquery or join?

850


how to shutdown mysql server? : Sql dba

743


Is sql considered coding?

758


What is schema in sql?

683


When is the update_statistics command used?

768






How do you select unique values in sql?

698


Can we have two clustered index on a table?

760


What is the difference between join and natural join?

653


what is subquery? : Sql dba

773


Is id a reserved word in sql?

858


Can primary key be changed?

665


Is foreign key mandatory?

711


What is trigger in sql?

784


how to create a test table in your mysql server? : Sql dba

682


What is the difference between left outer join and left join?

697