Write a SQL query which should fetch the 5th maximum salary
of an employee from the table?
Answers were Sorted based on User's Feedback
Answer / vsandhyana
Hi Hashmatulla Baig,
I think your query will not give the desired output. it
should be modify please refer below for the same.
SELECT empno, sal
FROM
(
select empno, sal, (ROW_number() OVER (order by sal desc)) R
from emp
order by sal desc
)
WHERE R = 5;
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / balanandam
select * from emp where sal =(select sal from(select sal,rank() over(order by sal desc) sal_rank from emp group by sal) where sal_rank=&rank)
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / dramesh511
select sal from emp e where 5=(select count(sal) from
emp e1 where e.sal<=e1.sal)
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / hashmatulla baig
SELECT empno, sal
FROM
(
select empno, sal, ROW_number() OVER (order by sal desc) R
from emp
order by sal desc
)
WHERE R = 5;
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / karthik murugeshan
SELECT B.Salary FROM (SELECT Salary FROM EMP)A,(SELECT
Salary FROM EMP)B
WHERE A.Salary>=B.Salary
GROUP BY B.Salary
HAVING COUNT(B.Salary)=5
Is This Answer Correct ? | 3 Yes | 3 No |
Answer / balanandam
select * from((select * from emp order by sal desc where rownum<=5)MINUS(select * from emp order by sal desc where rownum<=4))
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dhanu
SELECT DISTINCT SAL FROM EMP E WHERE 5>=(SELECT COUNT(DISTINCT SAL) FROM EMP A WHERE A.SAL<=E.SAL)ORDER BY SAL DESC
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sreenivasa
SELECT DEPTNO, ENAME, SAL FROM EMP A WHERE 4 = (SELECT COUNT
(B.SAL) FROM EMP B WHERE A.SAL < B.SAL)
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / pradeep nagireddy
select *
from(select rownum r,sal from emp order by sal desc)
where rownum = 5;
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / srcreddy
select* from
(select rownum rank,ename,sal from emp order by sal desc) where rank=5;
Is This Answer Correct ? | 0 Yes | 0 No |
Can you define a query subject?
Hi Friends, What is the Max no.of rows in a report & a page? If we have Master, Detail Reports, I have define drill through, Requirement is When i run Master Report it should run in HTML, when i drill through to detailed report it should get into PDF is it Possible in Cognos? Thank You Kumar
What are all the types of gateway used in Cognos?
What is set to be Cognos configuration?
What is Dynamic Grouping? what is diff between grouping n levelspan?
What are variable report studio?
What is the difference between Standard and Metrics folder?
What's use of a Master Detail report in Cognos? I mean what's the advantage? Please Explain.
suppose i want to do drill through a column only for the values which is having more than > 50000. how can i do that?
How to schedule the report in Cognos? And i have 2 users u1,u2. how to schedule the report for these 2 users(the 2 users will get result once for a week) but u1 get the result on every monday to his inbox,and u2 get the result on every wednesday to his inbox.
What is a Transformer?
--------------How to do Report Testing in Reports?