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

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

705


Explain aggregate functions are available there in sql?

752


What is query syntax?

717


Are there any features that are decommissioned in 11g that are not present in 11g?

1819


What is a sql select statement?

765






discuss about myisam key cache. : Sql dba

763


What is the difference between database trigger and stored procedure?

740


What is sql and db2?

729


Explain spool.

906


What is lookup table in sql?

766


How do you use a while loop in pl sql?

721


What are sql constraints?

788


How can we make an if statement within a select statement?

736


how to drop an existing table in mysql? : Sql dba

758


What is rename command in sql?

667