-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab2_1_ext.sql
42 lines (38 loc) · 1.38 KB
/
Lab2_1_ext.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
35
36
37
38
39
40
41
42
/*
Variant #10
group 651003
Kornienko Anastasia
*/
USE AdventureWorks2012;
GO
SELECT Employee.BusinessEntityID,
JobTitle,
ROUND(Rate, 0) AS RoundRate,
Rate
FROM HumanResources.Employee AS Employee
INNER JOIN HumanResources.EmployeePayHistory AS EmployeePayHistory
ON Employee.BusinessEntityID = EmployeePayHistory.BusinessEntityID
GROUP BY Employee.BusinessEntityID, JobTitle, Rate;
GO
SELECT Employee.BusinessEntityID,
JobTitle,
Rate,
RANK() OVER
(PARTITION BY Employee.BusinessEntityID ORDER BY RateChangeDate) AS ChangeNumber
FROM HumanResources.Employee AS Employee
INNER JOIN HumanResources.EmployeePayHistory AS EmployeePayHistory
ON Employee.BusinessEntityID = EmployeePayHistory.BusinessEntityID;
GO
SELECT Name, JobTitle, HireDate, BirthDate
FROM HumanResources.EmployeeDepartmentHistory AS EmployeeDepartmentHistory
INNER JOIN HumanResources.Department AS Department
ON EmployeeDepartmentHistory.DepartmentID = Department.DepartmentID
INNER JOIN HumanResources.Employee AS Employee
ON Employee.BusinessEntityID = EmployeeDepartmentHistory.BusinessEntityID
GROUP BY Name, JobTitle, HireDate, BirthDate
ORDER BY JobTitle ASC,
CASE
WHEN LEN(JobTitle) - LEN(REPLACE(LTRIM(RTRIM(JobTitle)), ' ', '')) = 0 THEN HireDate
WHEN LEN(JobTitle) - LEN(REPLACE(LTRIM(RTRIM(JobTitle)), ' ', '')) > 0 THEN BirthDate
END DESC;
GO