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 3nf normalization?
How to optimize stored procedures in sql server?
What is sql server replication? : sql server replication
Can sql servers link to other servers?
What is partitioned view?
What is difference between Datepart() and Datename() in SqlServer?
How to create dbo table in sql server?
When does a workload on SQL Azure get throttled?
What are the types of lock supported by ?
Explain about nested stored procedure?
How do you manipulate data?
What is user-defined function?
How you can change a cross join into an inner join?
What is indexing explain it with an example?
How many non clustered indexes there can be on table ?