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 |
Can pl sql procedure have a return statement?
How to fetch the rows by dynamicaly passing table name through cursor?
What is %s in sql?
How do you create a db file?
Can a table contain multiple foreign key’s?
How many sql statements are used?
what is timestamp in mysql? : Sql dba
What is a stored procedure ?
Can we enter data in a table in design view?
how to use in conditions? : Sql dba
Easy way to convert tableau "IF - ELSEIF" statements to Netezza "CASE" statements.
Is sql a microsoft product?