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
What is the difference between left outer join and left join?
Explain aggregate functions are available there in sql?
What is query syntax?
Are there any features that are decommissioned in 11g that are not present in 11g?
What is a sql select statement?
discuss about myisam key cache. : Sql dba
What is the difference between database trigger and stored procedure?
What is sql and db2?
Explain spool.
What is lookup table in sql?
How do you use a while loop in pl sql?
What are sql constraints?
How can we make an if statement within a select statement?
how to drop an existing table in mysql? : Sql dba
What is rename command in sql?