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 does a trigger work?
How do you remove duplicate records from a table?
what is a unique key ? : Sql dba
what is the difference difference between procedure and packages
Can a table contain multiple foreign key’s?
Is a table valued function object?
How do you identify a primary key?
column A column b | output 10 7 | 10 5 8 | 8 7 -9 | 7 3 5 | 5 0 6 | 6 Write a sql query to print such output.
What is trigger with example?
Describe different types of general function used in sql?
How is pl sql different from sql?
Why do we need a foreign key?
what is 'mysqlshow'? : Sql dba
what are the advantages of using stored procedures? : Sql dba
Define union, minus, union all, intersect ?