-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab2_1.sql
34 lines (30 loc) · 1.33 KB
/
Lab2_1.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Variant #9
group 651003
Kornienko Anastasia
*/
USE AdventureWorks2012;
GO
SELECT Employee.BusinessEntityID, JobTitle, SUM(Rate) AS AvarageRate FROM HumanResources.Employee AS Employee
INNER JOIN HumanResources.EmployeePayHistory AS EmployeePayHistory
ON Employee.BusinessEntityID = EmployeePayHistory.BusinessEntityID
GROUP BY Employee.BusinessEntityID, JobTitle;
GO
SELECT Employee.BusinessEntityID, JobTitle, Rate,
CASE WHEN Rate < 51 THEN 'Less or equal 50'
WHEN Rate > 100 THEN 'More than 100'
ELSE 'More than 50 but less or equal 100' END AS RateReport
FROM HumanResources.Employee AS Employee
INNER JOIN HumanResources.EmployeePayHistory AS EmployeePayHistory
ON Employee.BusinessEntityID = EmployeePayHistory.BusinessEntityID
GO
SELECT Name, MAX(Rate) AS MaxRate FROM HumanResources.Employee AS Employee
INNER JOIN HumanResources.EmployeePayHistory AS EmployeePayHistory
ON Employee.BusinessEntityID = EmployeePayHistory.BusinessEntityID
INNER JOIN (SELECT BusinessEntityID, Name FROM HumanResources.Department AS Department
INNER JOIN HumanResources.EmployeeDepartmentHistory AS EmployeeDepartmentHistory
ON EmployeeDepartmentHistory.DepartmentID = Department.DepartmentID)
AS Department ON Employee.BusinessEntityID = Department.BusinessEntityID
GROUP BY Name
ORDER BY MaxRate;
GO