-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00_sql_fundamentals_practice.sql
More file actions
285 lines (186 loc) · 4.33 KB
/
Copy path00_sql_fundamentals_practice.sql
File metadata and controls
285 lines (186 loc) · 4.33 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
USE AdventureWorks2016
/*
You have been tasked to return the first Name, Middle Name and last Name
from the person.Person table
*/
SELECT
firstname,
middlename,
lastname
FROM person.person --19972
/*
You manager will like you to use your answer from question 1
and rename the firstName to FName and the Last Name to LName
*/
SELECT
firstname AS FName,
lastname AS LName
FROM
person.person --19972
/*
Your manager wants you to write a query to return all the records
from the Person.CountryRegion
*/
SELECT *
FROM
person.countryregion --238
/*
Using your query result from question 3, the manager will like you to
rename the CountryRegionCode to display Region Code
*/
SELECT
countryregioncode AS 'Region Code'
FROM
person.countryregion --238
/*
Look at the query below, is the query correct, if yes what will be the result.
If NO, what is wrong with the Query. The intention is to get the Name as Store Name
*/
SELECT
Name AS Store Name,
SalesPersonID
FROM
[Sales].[Store]
-- It is not correct, SQL does not recognize 'Name' because of the order that it reads the code
/*
The query below is failing, and as a senior DA, your manager have asked you to
look at it and fixed it. What is wrong with the code and what is the correct code?
*/
SELECT
unit price, line total
FROM
Sales.SalesOrderDetail
--SQL does not recognize 'unit' or 'line'
SELECT
unitprice,
linetotal
FROM
sales.salesorderdetail -- 121,317
/*
Please provide a list of store names serviced by salespersonIDs 277,280 and 286
*/
SELECT
name
FROM
sales.store
WHERE salespersonid in (277, 280, 286) --154
/*
Please return all the records in the Person.Person table
*/
SELECT *
FROM
person.person --19972
/*
Using your answer from question 8, please return the first name, last name
and middle name from the person.person
*/
SELECT
firstname,
lastname,
middlename
FROM
person.person --19972
/*
Return all the records from the Person.CountryRegion where
the name is Australia
*/
SELECT *
FROM
person.countryregion
WHERE name = 'Australia' -- 1
/*
As a data analyst you have been task by your
manager to return the currencycode and name from
the Sales.Currency table. It is important that
as part of the request that you return only the name
names that is Naira
*/
SELECT
currencycode,
name
FROM
sales.currency
WHERE name = 'Naira' -- 1
/*
Please return all the records from the person.address table
*/
SELECT *
FROM
person.address --19614
/*
Using your code from question 12, please return only the city, postal code,
and the address ID
*/
SELECT
city,
postalcode,
addressid
FROM
person.address -- 19614
/*
It is the holiday season and your manager wants you to write a code
that will return all the records from the humanresource.employees table.
*/
SELECT *
FROM
humanresources.employee -- 290
/*
Using the answer you got from question 14, your manager now wants your to
only display the jobtitle, the birthdate, the vacation hours
and their sick leave hours of the employees.
*/
SELECT
jobtitle,
birthdate,
vacationhours,
sickleavehours
FROM
humanresources.employee -- 290
/*
Return the JobTitle ,BirthDate ,MaritalStatus, Gender from the
employee table that are married
*/
SELECT
jobtitle,
birthdate,
maritalstatus,
gender
FROM
humanresources.employee
WHERE maritalstatus = 'm' -- 146
/*
Return the JobTitle ,BirthDate ,MaritalStatus, Gender from the
employee table that are female
*/
SELECT
jobtitle,
birthdate,
maritalstatus,
gender
FROM humanresources.employee
WHERE gender = 'f' -- 84
/*
You work for a manufacturing company and the directors are about
to make a decision on designing of a new product,
they will like you to check in the production.product table to see if the
product names listed below exists in the database
Chainring Nut
Chain Stays
Touring End Caps
Flat Washer 1
*/
SELECT *
FROM production.product
WHERE name in ('chainring nut', 'chain stays', 'touring end caps', 'flat washer 1') -- 4
/*
The festive period is here and your company will like you to
keep track of the inventory of the company. Your manager wants
you to generate a dataset that will display the product ID,
shelf and quantity from the product.productinventory table.
*/
SELECT
productid,
shelf,
quantity
FROM
production.productinventory -- 1069