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 transact-sql ddl trigger?
Explain the usage of floor function in sql server.
what are the different types of SSRS reports?
how would you improve etl (extract, transform, load) throughput?
What is shared lock?
How to define and use table alias names in ms sql server?
What is transaction server implicit?
What is the architecture of ms sql reporting service?
You want to check the syntax of a complicated update sql statement without executing it. What command should you use?
How to turn on the mssql api module in php?
What is the difference between DataRow.Delete() and DataRow.Remove()?
As a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this?
When should you use an instead of trigger?
Explain what stored procedure sp_replcounters is used for? : sql server replication
What is recompile sql server?