select top 3 sal from each dept?

Answers were Sorted based on User's Feedback



select top 3 sal from each dept?..

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

select top 3 sal from each dept?..

Answer / anil

select * from(select ename,deptno,sal from emp order by sal desc) where rownum<=3

Is This Answer Correct ?    0 Yes 1 No

select top 3 sal from each dept?..

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

select top 3 sal from each dept?..

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

select top 3 sal from each dept?..

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

select top 3 sal from each dept?..

Answer / sen

select *
(select sal from emp
order by 1 desc)
where rownum < 4

Is This Answer Correct ?    1 Yes 13 No

select top 3 sal from each dept?..

Answer / asksam

Easy method to find top 3 sal -

Select distinct top 3 (sal) from emp order by sal desc

Is This Answer Correct ?    10 Yes 27 No

Post New Answer

More SQL PLSQL Interview Questions

Is sqlite thread safe?

0 Answers  


How to change the order of columns in Oracle SQL Plus ?

0 Answers   MCN Solutions,


How do sql databases work?

0 Answers  


How to write a single statement that concatenates the words ?hello? And ?world? And assign it in a variable named greeting?

0 Answers  


Mention what does plvtab enables you to do when you showthe contents of pl/sql tables?

0 Answers  






What is cold data?

0 Answers  


explain the options of myisamchk to improve the performance of a table. : Sql dba

0 Answers  


Why are cursors used?

0 Answers  


What is percent sign in sql?

0 Answers  


What is difference between db2 and sql?

0 Answers  


In a table i have columns A,B,C and i have a composite index on columns A,B if so will the following query uses index or not? SELECT sal,name FROM <table_name> WHERE A=<value> AND B=<value> AND C=<value>;

2 Answers   Mastek,


Are there any features that are decommissioned in 11g that are not present in 11g?

0 Answers  


Categories