write query for fourth maximum salary from employee table
Answers were Sorted based on User's Feedback
Answer / anish tuladhar
select
distinct salary
from
(
select
DENSE_RANK() over(order by salary desc) as rnk,
salary
from
employee
) a
where
rnk = 4
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prabhjeet singh sethi
select * from
(select rank(salary) over (partition by employee order by salary desc) as top_salary, employee from table
group by employee)
where top_salary = 4
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / icedrop
select top 1 salary from (select distinct top 4 Salary from tablename order by salary desc ) result order by salary
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / santhosh
;with result as
(
--use dense_rank instead of row_number or rank
select salary, DENSE_RANK() over (order by salary desc) as denserank
from Employees
)
select top 1 * from result
where denserank = 4
Is This Answer Correct ? | 0 Yes | 0 No |
What are the types of database recovery models?
Where are magic tables stored ? Is it in the same database where it is created ?
How to create and drop temp table in sql server?
1. What is CUBE Operator? 2. what are the new data types are available in sql server 2008? 3. Inisde a nested queries, how many subqueries u can have?
Can a table be moved to different filegroup?
How to delete existing rows in a table?
What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting is possible?
What is #table in sql server?
Can sql server be linked with other servers like oracle?
Why do we use stored procedures in sql server?
Why transaction is important?
What is partition in sql server?