Find top Nth employee from each department in terms of
salary?
Answer Posted / chandra sekhar
CREATE A EMPLOYEES TABLE WITH THE COLUMNS
EMPLOYEEID,EMPLOYEENAME,DEPARTMENT,SALARY
AND INSERT THE RECORDS INTO THE TABLE
with cte
as (
select dense_RANK() over(partition by department order by salary desc) as Rank,
employeeID,employeename,department,salary from
Employees)
select x.employeeID,
x.employeename,
x.department,
x.salary,
x.rank
from cte x
where x.Rank=2
order by x.Salary
NOTE:here i am finding 2nd highest salary from the each department
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Explain the concept of view and Types of views in SQL server?
What are data regions?
Explain data warehousing in sql server?
optimization techinques
Can you give me some DBCC command options?(Database consistency check) - DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.
What are the advantages of using third-party tools?
What is row_number () and partition by in sql server?
What is mean by candidate key?
How many triggers are possible per table?
explain different types of joins? : Sql server database administration
Explain the concept of recursive stored procedure.
What are types of subqueries?
when would you go for denormalization? : Sql server database administration
What is service broker? : sql server database administration
What have included columns when we talk about sql server indexing?