i need department wise top 2 employees salary.which logic
i will use
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / manish gupta
select deptno,sal from (select * from emp order by sal
desc) where rownum<3
union
select deptno,sal from (select * from emp order by sal
desc) where rownum<3 and deptno not in(20);
considering scott table in db.
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / priyank shah
SELECT * FROM (SELECT ENAME,SAL FROM EMP ORDER BY SAL
DESC)
WHERE ROWNUM < 3
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / mukesh kumar
SELECT * FROM (SELECT NAME,SALARY FROM EMP ORDER BY SALARY
DESC)
WHERE ROWNUM < 3
Is This Answer Correct ? | 1 Yes | 7 No |
Answer / ramya p
select deptno, max(sal) from (select * from emp order by
sal desc)
where rownum < 3
group by deptno
order by max(sal) desc;
Is This Answer Correct ? | 5 Yes | 12 No |
Answer / ramya p
Select * from emp where sal in
(Select * From (Select sal from emp order by sal desc)
Where rownum < 3) order by sal desc;
Is This Answer Correct ? | 6 Yes | 18 No |
can i give user defined exception in a package
Why do we need pl sql?
What is localdb mssqllocaldb?
What is the maximum number of columns in sql table?
how to retrieve the top 3 salaries of the table using rownum
What is dynamic query?
Why do we need cursors in pl sql?
How will we see framework of a table?
What is trigger and how to use it in sql?
How do you rank data in sql?
What pl/sql package consists of?
can we write stored function in out parameters? how to call through select statement? how to written more than one value plz give the exmple?