select top 3 sal from each dept?
Answers were Sorted based on User's Feedback
Answer / avinesh gupta
select top 3 sal,depno from emp where deptno in
(
select deptno from emp group by deptno
)
order by sal desc
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sambu
select r.sal,r.rank,r.dept high from
(select deptno,sal,dense_rank() over (partition by deptno
order by sal desc) rank
from emp) r
where r.rank=3;
The above query gives the following result
DEPTNO SAL HIGHEST
------ ----- -------
10 1300 3
20 1100 3
30 1500 3
| Is This Answer Correct ? | 3 Yes | 7 No |
Answer / kishore
select * from (
select sal,rownum as num from (select sal from
emp order by sal desc))
where num <=3;
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / neetika vardhan
SELECT DEPT, MAX(SAL)
FROM EMP
WHERE SAL NOT IN (SELECT MAX(SAL) FROM EMP GROUP BY DEPT)
GROUP BY DEPT
UNION
SELECT DEPT, MAX(SAL)
FROM EMP
GROUP BY DEPT
UNION
SELECT DEPT, MAX(SAL)
FROM EMP
WHERE SAL NOT IN
(SELECT MAX(SAL)
FROM EMP
WHERE SAL NOT IN (SELECT MAX(SAL) FROM EMP GROUP
BY DEPT)
GROUP BY DEPT
UNION
SELECT MAX(SAL) FROM EMP GROUP BY DEPT)
GROUP BY DEPT
| Is This Answer Correct ? | 0 Yes | 6 No |
Answer / sen
select *
(select sal from emp
order by 1 desc)
where rownum < 4
| Is This Answer Correct ? | 1 Yes | 13 No |
Why we use cross join?
How long it takes to learn pl sql?
What are the types of queries in sql?
what are the differences between procedure-oriented languages and object-oriented languages? : Sql dba
Suppose There is a string A.B....C.......D.........E........F In this string dots (.) are not having fixed count in between of string. I want the output to have string with one dot between. I.e. A.B.C.D.E.F
Can you inner join the same table?
Explain clause in sql?
How do you declare a variable in pl sql?
Is inner join same as self join?
four procedures is are there should i write their in a package
How do you truncate?
Is merge a dml statement?
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)