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 |
Table Order_Name has a column Order_Date which gives the date & Time at which the order is passed.Find the table to write a query to find out the latest order.
what is explain plan?
How to count the no of records of a table without using COUNT function?
What is sql catalog?
How to come back in normal stage in Mutating Table if mutating table is locked or update data?
What steps server process has to take to execute an update statement?
Can a varchar be a primary key?
what is the use of HASH, LIST partitions?
one of the column in my table contains the data like SAL ---- 1000 1000 2000 3000 3000 So my requirement is i want output like SAL --- 1000 2000 3000 it mean i want to delete duplicate rows in the table permanently and i want output in the above formatow should u write query?
What is the limitation on the block size of pl/sql?
What is the use of <> sql?
Define overloaded procedure?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)