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
What is bcp? When does it use?
What stored by the msdb?
Explain what is raid and what are different types of raid levels?
What are sql servers used for?
What is a full text index?
What is log in sql server?
How can you set the threshold at which sql server will generate keysets asynchronously?
What is a covering index?
What does set rowcount do?
What are the recovery models for a database?
How to create an multi-statement table-valued function?
Explain the ways to controlling cursor behavior?
What is a trigger what are the advantages of trigger?
What is the difference between a unique key and primary key?
Does hive support indexing?