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 insert a new row into a table with "insert into" statements in ms sql server?
How should i optimize the time for execution of stored procedure having single input and many output from the different tables?
Mention what are the core components of ssrs?
What is the log shipping?
What is the difference between NOROW and LOCKROW?
Explain database normalization?
How to convert a table data in XML format in sql server?
after migrating the dts packg to ssis by using migrtn wizrd in 2005. iam not able to open ssis pack and getting error. what r those errors? how to resolve?
How to loop through result set objects using odbc_fetch_row()?
What are the advantages of having an index on the sql server?
Which sql server table is used to hold the stored procedure scripts?
What are rest-style architecture's?
What is schemabinding a view?
write an SQL query to list the employees who joined in the month of January?
how would you write a sql query to compute a frequency table of a certain attribute involving two joins? What changes would you need to make if you want to order by or group by some attribute? What would you do to account for nulls?