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 can we debug in PL/SQL?
what does the t-sql command ident_current does? : Transact sql
What is difference between mysql and postgresql?
Why are aggregate functions called so?
Can I create table without primary key?
Is oracle sql free?
what are the authentication modes in sql server? : Sql dba
What are the differences between implicit and explicit cursors?
Which is faster truncate or drop?
what is a trigger in mysql? Define different types of trigger. : Sql dba
Who developed sql?
What is difference between cursor and trigger?
What is crud stand for?
What is sql stand for?
Is it possible to pass parameters to triggers?