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

wtite down triggr not any entry on Sunday

2 Answers   NIT,


What are the parts of a basic sql query?

0 Answers  


how to delete duplicate rows from a join tables(I have three tables on that join) how do you know which join is need to be used? The select statement I have is: SELECT gc_skill_type.skill_type, gc_area_tec.area, gc_technology.technology, gc_technology.id_technology, gc_area_tec.id_area_tec FROM gc_skill_type, gc_area_tec, gc_technology WHERE gc_area_tec.id_skill_type (+) = gc_skill_type.id_skill_type AND gc_technology.id_area_tec (+) = gc_area_tec.id_area_tec order by gc_skill_type.skill_type asc, gc_area_tec.area asc, gc_technology.technology asc

1 Answers   IAS,


Why do we use joins?

0 Answers  


What is a join?Explain the different types of joins?

6 Answers   Bank Of India, CitiGroup, Google, ICICI, Saama Tech, SkyTech, TCS,






Explain the difference between sql and mysql.

0 Answers  


What is procedure and function?

0 Answers  


how to find the First and Last Observation from the table: Ex: OBS Name Sal Ans like: OBS Name Sal 105 E 5000--> 105 E 5000 102 B 2000 104 D 4000 103 C 3000 101 A 1000--> 104 D 4000

4 Answers  


How pl/sql source code can be protected?

3 Answers  


What is the Subquery?

4 Answers  


Is oracle and sql same?

0 Answers  


Is left join faster than join?

0 Answers  


Categories