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

Answer Posted / nitin tomer

Query without using analytic function:

SELECT dept_id, MAX(salary)
FROM EMPLOYEE_DEPT WHERE rowid NOT IN (SELECT MAX(rowid) FROM EMPLOYEE_DEPT GROUP
BY dept_id )
GROUP BY dept_id
UNION
SELECT dept_id, MAX(salary)
FROM EMPLOYEE_DEPT
GROUP BY dept_id;

using row_number() function:

SELECT NAME,DEPT_ID,SALARY,RNM FROM
(SELECT NAME,DEPT_ID,SALARY,ROW_NUMBER()OVER(PARTITION BY DEPT_ID ORDER BY SALARY DESC) AS RNM
FROM EMPLOYEE_DEPT)WHERE RNM<3;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we debug in PL/SQL?

663


what does the t-sql command ident_current does? : Transact sql

546


What is difference between mysql and postgresql?

518


Why are aggregate functions called so?

516


Can I create table without primary key?

531






Is oracle sql free?

542


what are the authentication modes in sql server? : Sql dba

537


What are the differences between implicit and explicit cursors?

521


Which is faster truncate or drop?

562


what is a trigger in mysql? Define different types of trigger. : Sql dba

554


Who developed sql?

570


What is difference between cursor and trigger?

559


What is crud stand for?

570


What is sql stand for?

577


Is it possible to pass parameters to triggers?

575