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 to drop an existing stored procedure in ms sql server?
What is scalar user-defined function?
How do I shrink an ldf file?
What is the difference between primary key and unique constraints?
define and explain the differences between clustered and non-clustered indexes.
What is the data type of time?
What are drilldown reports?
What is the difference between migration and upgradation in sql server?
What are the differences between stored procedure and the dynamic sql?
how many type of indexing in database?
What protocol does sql server use?
What are the requirements to use odbc connections in php scripts?
How to query multiple tables jointly?
What is the importance of a recovery model?
What is a full text index?