Please get the 4 th maximum salary from a table without
using any sql keyword (TOP,MAX are mot allowed)
Answer Posted / pradeep
DECLARE @test TABLE(Empnm VARCHAR(10), Salary VARCHAR(10))
INSERT INTO @test (Empnm, Salary )
SELECT 'A', '200'
UNION ALL
SELECT 'B', '300'
UNION ALL
SELECT 'A', '200'
UNION ALL
SELECT 'B', '300'
UNION ALL
SELECT 'C', '400'
UNION ALL
SELECT 'C', '400'
UNION ALL
SELECT 'E', '100'
UNION ALL
SELECT 'D', '500'
SELECT * FROM @test
SELECT Empnm, Salary, (SELECT COUNT(DISTINCT(SALARY)) FROM
@test AS B WHERE A.Salary <= B.SALARY)
FROM @test AS A
GROUP BY Empnm, Salary
HAVING 4 = (SELECT COUNT(DISTINCT(SALARY)) FROM @test AS B
WHERE A.Salary <= B.SALARY)
| Is This Answer Correct ? | 9 Yes | 2 No |
Post New Answer View All Answers
How do I create a trace in sql server?
What is field with example?
What is the difference between ‘having’ clause and a ‘where’ clause?
Tell me what are the advantages of using stored procedures?
Can sql servers linked to other servers?
What is the sql case statement used for?
Is natural join and equi join same?
How to find related tables in sql server?
What are some of the pros and cons of not dropping the sql server builtinadministrators group? : sql server security
What is 1nf 2nf?
Do you know what is openxml in sql server?
How can we determine what objects a user-defined function depends upon?
Explain about builtinadministrator?
What is dknf in normalization form?
How to apply filtering criteria at group level with the having clause in ms sql server?