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
How do you create a unique index?
name 3 ways to get an accurate count of the number of records in a table? : Sql dba
What is a table?
What does the hierarchical profiler does?
What is package in pl sql with an examples?
Which join is default?
Is primary key always clustered index?
Is sql better than access?
What is oracle and pl sql?
which types of join is used in sql widely? : Sql dba
how to rename an existing column in a table? : Sql dba
What is an index? What are the types of indexes? How many clustered indexes can be created on a table?
What is exit statement?
what is the difference between nested subquery and correlated subquery?
explain the difference between delete , truncate and drop commands? : Sql dba