-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04. Basic CRUD Homework.sql
190 lines (157 loc) · 2.75 KB
/
04. Basic CRUD Homework.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
USE SoftUni
--P2
SELECT * FROM Departments
--P3
SELECT [Name] FROM Departments
--P4
SELECT FirstName, LastName, Salary FROM Employees
--P5
SELECT FirstName, MiddleName, LastName FROM Employees
--P6
SELECT
FirstName + '.' + LastName + '@softuni.bg' AS 'Full Email Address'
FROM Employees
--P7
SELECT
DISTINCT
Salary
FROM Employees
--P8
SELECT
*
FROM Employees
WHERE JobTitle IN ('Sales Representative')
--P9
SELECT
FirstName,
LastName,
JobTitle
FROM Employees
WHERE Salary BETWEEN 20000 AND 30000
--P10
SELECT
FirstName + ' ' + MiddleName + ' ' + LastName AS 'Full Name'
FROM Employees
WHERE Salary IN (25000, 14000, 12500, 23600)
SELECT * FROM Employees
--P10 with check for null in columns
SELECT
CASE WHEN FirstName IS NULL THEN '' ELSE FirstName END +
CASE WHEN MiddleName IS NULL THEN '' ELSE ' ' + MiddleName END +
CASE WHEN LastName IS NULL THEN '' ELSE ' ' + LastName END
FROM Employees
WHERE Salary IN (25000, 14000, 12500, 23600)
--P11
SELECT
FirstName,
LastName
FROM Employees
WHERE ManagerID IS NULL
--P12
SELECT
FirstName,
LastName,
Salary
FROM Employees
WHERE Salary >= 50000
ORDER BY Salary DESC
--P13
SELECT
TOP(5)
FirstName,
LastName
FROM Employees
WHERE Salary >= 50000
ORDER BY Salary DESC
--P14
SELECT
FirstName,
LastName
FROM Employees
WHERE DepartmentID <> 4
--P15
SELECT
*
FROM Employees
ORDER BY Salary DESC,
FirstName ASC,
LastName DESC,
MiddleName ASC
GO
--P16
CREATE VIEW V_EmployeesSalaries AS
SELECT
FirstName,
LastName,
Salary
FROM Employees
GO
SELECT * FROM V_EmployeesSalaries
GO
--P17
CREATE VIEW V_EmployeeNameJobTitle AS
SELECT
FirstName + ' ' +
CASE WHEN MiddleName IS NULL THEN '' ELSE MiddleName END + ' ' +
LastName
AS 'Full Name',
JobTitle
FROM Employees
GO
DROP VIEW V_EmployeeNameJobTitle
GO
SELECT * FROM V_EmployeeNameJobTitle
--P18
SELECT
DISTINCT
JobTitle
FROM Employees
--P19
SELECT
TOP(10)
*
FROM Projects
ORDER BY [StartDate], [Name]
--P20
SELECT
TOP(7)
FirstName,
LastName,
HireDate
FROM Employees
ORDER BY HireDate DESC
--P21
UPDATE Employees
SET Salary = Salary * 1.12
WHERE DepartmentID IN(11, 4, 2, 1)
SELECT Salary FROM Employees
USE SoftUni
--P22
USE [Geography]
SELECT
DISTINCT
PeakName
FROM Peaks
--P23
SELECT
TOP(30)
[CountryName],
[Population]
FROM Countries
WHERE ContinentCode = 'EU'
ORDER BY [Population] DESC,
CountryName ASC
SELECT * FROM Countries
--P24
SELECT
CountryName,
CountryCode,
CASE WHEN CurrencyCode = 'EUR' THEN 'Euro' ELSE 'Not Euro' END AS 'Currency'
FROM Countries
ORDER BY CountryName
--P25
USE Diablo
SELECT
[Name]
FROM Characters
ORDER BY [Name]