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 get the definition of a view out of the sql server?
Does index speed up select statements?
Explain different types of collation sensitivity?
What is 3nf normalization form?
What is query and its types?
Name three of the features managed by the surface area configuration tool? : sql server security
What is the function of inner join?
what is denormalization and when would you go for it? : Sql server database administration
How we can compare two database data?
What do mean by xml datatype?
What is row_number () and partition by in sql server?
What are the different types of triggers in SQL SERVER?
What are locks in sql?
How do I debug a stored procedure in sql server?
List types of tables in SQL Azure?