Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to get top 3 salaries from emlpoyee table department wise

$
0
0

Hi,

I want to get top 3 salaries from each of the department. what can be the query?

Create Table Employee
(
	EmployeeID Int Identity Primary Key,
	EmployeeName Varchar(10),
	DepartmentID Int ,
	Salary Money
)

insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N1', 1, 1000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N2', 1, 2000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N3', 1, 3000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N4', 1, 4000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N5', 1, 5000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N6', 1, 6000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N7', 1, 7000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N8', 1, 8000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N9', 1, 9000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N10', 1, 10000)

insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N1', 2, 1000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N2', 2, 2000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N3', 2, 3000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N4', 2, 4000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N5', 2, 5000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N6', 2, 6000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N7', 2, 7000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N8', 2, 8000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N9', 2, 9000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N10',2, 10000)


insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N1', 3, 1000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N2', 3, 2000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N3', 3, 3000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N4', 3, 4000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N5', 3, 5000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N6', 4, 6000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N7', 4, 7000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N8', 4, 8000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N9', 4, 9000)
insert into Employee(EmployeeName, DepartmentID, Salary) Values ('N10',4, 10000)

I want Output like:

EmpID EmpName DeptID, Salary
8 ,  N8,    1,     8000.00
9 ,  N9,    1,     9000.00
10,  N10,   1,     10000.00

18,  N8,    2,     8000.00
19,  N9,    2,     9000.00
20,  N10,   2,     10000.00

23,  N3,    3,     3000.00
24,  N4,    3,     4000.00
25,  N5,    3,     5000.00

28,  N8,    4,     8000.00
29,  N9,    4,     9000.00
30,  N10,   4,     10000.00


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>