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 will you distinguish a global variable with a local variable in pl/sql?
Can unique keys be null?
Why is %isopen always false for an implicit cursor?
What is sql prepared statement?
Does group by remove duplicates?
How many types of index are there?
Can we group by two columns in sql?
What are the types of sql commands?
Is sql similar to python?
How delete all data from table in sql?
Is trigger a stored procedure?
Explain character-manipulation functions?
What is the mutating table and constraining table?
How would you convert date into julian date format?
How to get help at the sql prompt?