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 |
Why stored procedure is better than query?
What is package in pl sql with an examples?
can a stored procedure call itself or recursive stored procedure? How much level sp nesting is possible? : Sql dba
What is a transaction?
Can you load data into multiple tables at once? : aql loader
What is error ora-01000: maximum open cursors exceeded
What is trigger types of trigger?
What program will open a mdb file?
how many values can the set function of mysql take? : Sql dba
What are data types in pl sql?
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
What is the maximum database size for sql express?
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)