-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwec19b_assignment1.sql
More file actions
192 lines (169 loc) · 2.95 KB
/
wec19b_assignment1.sql
File metadata and controls
192 lines (169 loc) · 2.95 KB
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
191
192
/*wec19b Assignment 1*/
/*I affirm that this is *MY* code!*/
/*Problem 1*/
/*1a*/
SELECT
last_name,
first_name,
phone_number
FROM
employees;
/*Hmm...looks like some of these people have no phone numbers on record.
I wonder if this will be important later.*/
/*1b*/
--To start, we have 40 records/rows displayed in the code for 1(a).
/*1c*/
SELECT
last_name AS [Last Name],
first_name AS [First Name],
phone_number AS [Contact]
FROM
employees;
/*1d*/
SELECT
first_name AS [First Name],
last_name AS [Last Name],
phone_number AS [Contact]
FROM
employees;
/*1e*/
SELECT
employee_id,
department_id,
salary
FROM
employees
ORDER BY
department_id ASC;
/*1f*/
SELECT
employee_id,
department_id,
salary
FROM
employees
ORDER BY
department_id DESC,
salary DESC;
/*1g*/
SELECT
employee_id,
salary
FROM
employees
ORDER BY
salary DESC
LIMIT 6;
/*1h*/
--The employee ID of the person with the fourth-highest salary is 145.
/*Problem 2*/
/*2a*/
SELECT
employee_id,
salary,
salary/12 AS [monthly_salary],
(salary/12)*0.062 AS [social_security],
(salary/12)*0.0145 AS [medicare]
FROM
employees;
--I ran a few of these arithmetically myself, and they should be correct.
/*2b*/
SELECT
employee_id,
salary,
(salary*1.055)+1200 AS [new_salary]
FROM
employees
ORDER BY
new_salary ASC;
/*2c*/
SELECT
last_name,
first_name,
email,
employee_id,
salary,
(salary*1.055)+1200 AS [new_salary]
FROM
employees
WHERE
department_id IS 10
ORDER BY
salary DESC;
/*2d*/
SELECT
last_name,
first_name,
hire_date
FROM
employees
WHERE
(Date(hire_date) > '1994-12-31') AND (Date(hire_date) < '1998-01-01')
ORDER BY
hire_date ASC;
/*2e*/
--The last employee hired in 1996 was John Russell
/*2f*/
SELECT
last_name,
first_name,
job_id
FROM
employees
WHERE
job_id = 5 OR job_id=6 OR job_id=14 OR job_id=17
ORDER BY
job_id ASC;
/*2g*/
SELECT
first_name,
last_name
FROM
employees
WHERE
last_name LIKE '%y'
ORDER BY
last_name DESC;
/*2h*/
--With the above query, the first name that appears in the table is Den Raphaely
/*Problem 3*/
/*3a*/
SELECT
employee_id,
email,
salary,
department_id
FROM
employees
WHERE
(department_id = 8 OR department_id = 10) AND salary > 10000;
/*3b*/
--Three employees were pulled with the above query.
/*3c*/
SELECT
first_name,
last_name,
job_id
FROM
employees
WHERE
(job_id = 9 OR job_id = 13 OR job_id = 19) AND (first_name LIKE 'A%' OR last_name LIKE '%s%')
ORDER BY
job_id ASC,
last_name ASC;
/*3d*/
--The name of the last employee returned with the above query is Matthew Weiss.
/*3e*/
SELECT
employee_id,
salary,
CASE
WHEN salary < 4500 THEN 'Low'
WHEN salary BETWEEN 4501 AND 8000 THEN 'Below Average'
WHEN salary BETWEEN 8001 AND 10000 THEN 'Above Average'
ELSE 'High'
END AS salary_class
FROM
employees
ORDER BY
salary ASC;