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 I edit a stored procedure?
Can pl sql procedure have a return statement?
What is the trigger in sql?
What is sorting in sql?
Explain the significance of the & and && operators in pl sql.
hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews
How can we implement rollback or commit statement in a trigger?
What is dense_rank in sql?
Is sql similar to python?
What are the differences between in and exists clause?
Table 1: col1 Timestamp ---------------- 01-mar-2012 11:12:46 Table 2: col2 Timestamp -------------------- 01-mar-2012 11:12:10 01-mar-2012 11:11:23 Write a query to display a row with table2 col2 value less than tabl1 col1 value. Maximum timestamp value previous to table1 col1 value. Display a result as: Col1 col2 ----- ----- 01-mar-2012 11:12:46 01-mar-2012 11:12:10
Is oracle and sql same?
How to use transactions efficiently : transact sql
What is relationship? How many types of relationship are there?
How do I run a sql trace?