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
What is clustered index
How to convert character strings into numeric values?
How efficient you are in oracle and SQL server?
What is a view in sql?
How to enter binary string literals in ms sql server?
What are the different types of subquery?
What are wait types?
Why use identity in sql server?
How to remove duplicate rows from table except one?
How to rebuild the master database?
Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?
What is in place upgrade in sql server?
what is the Ticketing tool used in Wipro technologies at Bangalore...???
How do I find the sql server version?
How can we solve concurrency problems?