adspace


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


Please Help Members By Posting Answers For Below Questions

What is clustered index

1092


How to convert character strings into numeric values?

1196


How efficient you are in oracle and SQL server?

1269


What is a view in sql?

1046


How to enter binary string literals in ms sql server?

1255


What are the different types of subquery?

1239


What are wait types?

1260


Why use identity in sql server?

1209


How to remove duplicate rows from table except one?

1096


How to rebuild the master database?

1175


Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?

1031


What is in place upgrade in sql server?

1137


what is the Ticketing tool used in Wipro technologies at Bangalore...???

8237


How do I find the sql server version?

1114


How can we solve concurrency problems?

1129