-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlabtest_b2.html
More file actions
539 lines (474 loc) · 12.7 KB
/
labtest_b2.html
File metadata and controls
539 lines (474 loc) · 12.7 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<!DOCTYPE html>
<html>
<head>
<title>Lab Test 01</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f2f2f2;
}
h1,
h2,
ol,
ul,
p {
margin-top: 20px;
margin-bottom: 10px;
}
h1 {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
}
h2 {
font-size: 22px;
}
ul {
list-style-type: disc;
margin-left: 30px;
}
ol {
list-style-type: decimal;
margin-left: 30px;
}
li {
margin-bottom: 5px;
}
p {
font-size: 18px;
}
table {
border-collapse: collapse;
border: 2px solid black;
}
th,
td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #ddd;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
td:first-child,
th:first-child {
border-left: none;
}
td:last-child,
th:last-child {
border-right: none;
}
body {
font-family: sans-serif;
display: grid;
height: 100vh;
place-items: center;
}
.base-timer {
position: relative;
width: 300px;
height: 300px;
}
.base-timer__svg {
transform: scaleX(-1);
}
.base-timer__circle {
fill: none;
stroke: none;
}
.base-timer__path-elapsed {
stroke-width: 7px;
stroke: grey;
}
.base-timer__path-remaining {
stroke-width: 7px;
stroke-linecap: round;
transform: rotate(90deg);
transform-origin: center;
transition: 1s linear all;
fill-rule: nonzero;
stroke: currentColor;
}
.base-timer__path-remaining.green {
color: rgb(65, 184, 131);
}
.base-timer__path-remaining.orange {
color: orange;
}
.base-timer__path-remaining.red {
color: red;
}
.base-timer__label {
position: absolute;
width: 300px;
height: 300px;
top: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 48px;
}
</style>
</head>
<body>
<h1>CSE 3110: Database Systems Laboratory - Lab Test 01 <br>
Time: 30 min
</h1>
<div style="max-width: 800px; margin: 0 auto;">
<h2>Table Description</h2>
<table>
<tr>
<th>Table Name</th>
<th>Columns</th>
</tr>
<tr>
<td>Customer</td>
<td>ID<br>Name<br>Contact</td>
</tr>
<tr>
<td>Goods</td>
<td>Goods_ID<br>Goods_Name<br>Price</td>
</tr>
<tr>
<td>Order</td>
<td>Order_Date<br>Customer_ID<br>Goods_ID</td>
</tr>
</table>
<ul>
<li>Make ID and GOODS_ID as the primary key and don’t allow the columns to take NULL values.
</li>
<li>Make CUSTOMER_ID and GOODS_ID the foreign key of Order table referencing ID of Customer and GOODS_ID of
Goods table respectively</li>
<li>Apply some domain integrity techniques so that you can’t put negative value in the PRICE column of Goods
table.</li>
<li>Apply some domain integrity techniques so that if you delete a record in the customer table, related
records in Order table will automatically deleted.</li>
</ul>
<div class="container my-5">
<div class="row">
<div class="col-md-17 mx-auto">
<div class="pre-scrollable">
<pre>
CREATE TABLE Customer (
ID INT NOT NULL PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Contact VARCHAR(50) NOT NULL
);
CREATE TABLE Goods (
Goods_ID INT NOT NULL PRIMARY KEY,
Goods_Name VARCHAR(50) NOT NULL,
Price DECIMAL(10, 2) NOT NULL CHECK (Price >= 0)
);
CREATE TABLE Order (
Order_Date DATE NOT NULL,
Customer_ID INT NOT NULL,
Goods_ID INT NOT NULL,
PRIMARY KEY (Customer_ID, Goods_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customer(ID) ON DELETE CASCADE,
FOREIGN KEY (Goods_ID) REFERENCES Goods(Goods_ID) ON DELETE CASCADE
);
</pre>
</div>
</div>
</div>
</div>
<h2>Queries</h2>
<table>
<thead>
<tr>
<th>Question</th>
</tr>
</thead>
<tbody>
<tr>
<td>Insert minimum three rows in above tables.
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
INSERT INTO Customer (ID, Name, Contact, Address)
VALUES (1, 'John Doe', '555-1234', '123 Main St');
INSERT INTO Customer (ID, Name, Contact, Address)
VALUES (2, 'Jane Smith', '555-5678', '456 Oak Ave');
INSERT INTO Customer (ID, Name, Contact, Address)
VALUES (3, 'Bob Johnson', '555-9012', '789 Elm St');
INSERT INTO Customer (ID, Name, Contact, Address)
VALUES (4, 'Alice Brown', '555-3456', '321 Pine St');
-- Insert data into the Goods table
INSERT INTO Goods (Goods_ID, Goods_Name, Price)
VALUES (1, 'Widget', 10.99);
INSERT INTO Goods (Goods_ID, Goods_Name, Price)
VALUES (2, 'Gadget', 19.99);
INSERT INTO Goods (Goods_ID, Goods_Name, Price)
VALUES (3, 'Thingamajig', 8.99);
INSERT INTO Goods (Goods_ID, Goods_Name, Price)
VALUES (4, 'Doohickey', 14.99);
-- Insert data into the Order table
INSERT INTO Order (Order_Date, Customer_ID, Goods_ID)
VALUES ('2023-03-19', 1, 1);
INSERT INTO Order (Order_Date, Customer_ID, Goods_ID)
VALUES ('2023-03-20', 1, 2);
INSERT INTO Order (Order_Date, Customer_ID, Goods_ID)
VALUES ('2023-03-21', 2, 3);
INSERT INTO Order (Order_Date, Customer_ID, Goods_ID)
VALUES ('2023-03-22', 3, 4);
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>To retrieve the names of all goods that have the letter "i" in their name and the customer's
name contains the letter "j". <br>
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
SELECT g.Goods_Name FROM Goods g
JOIN Order o ON g.Goods_ID = o.Goods_ID
JOIN Customer c ON o.Customer_ID = c.ID
WHERE g.Goods_Name LIKE '%i%'
AND c.Name LIKE '%j%';
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Find the total number of customers in the Customer table and the details of the customer with ID
102, including their contact number.
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
SELECT COUNT(*) as total_customers, Name, Contact FROM Customer
WHERE ID = 102;
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Retrieve the name and contact information of all customers who have purchased the goods with the
lowest price in the Goods table.
<div class="container my-3">
<div class="row">
<div class="col-md-19 mx-auto">
<div class="pre-scrollable">
<pre>
SELECT C.Name, C.Contact
FROM Customer C
JOIN Order O ON C.ID = O.Customer_ID
JOIN (SELECT MIN(Price)
as min_price FROM Goods) G ON G.min_price =
(SELECT Price FROM Goods WHERE Goods_ID = O.Goods_ID)
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Find the customers who have not placed any orders yet.
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
SELECT C.Name, C.Contact
FROM Customer C
WHERE C.ID NOT IN (SELECT DISTINCT Customer_ID FROM Order)
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Find the name of the customer who placed the most expensive order.
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
SELECT c.Name
FROM Customer c
JOIN Order o ON c.ID = o.Customer_ID
JOIN Goods g ON g.Goods_ID = o.Goods_ID
WHERE g.Price = (SELECT MAX(Price) FROM Goods)
ORDER BY g.Price DESC
LIMIT 1;
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>List all customers who have made more than 2 orders.
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
SELECT c.Name, COUNT(*) as num_orders
FROM Customer c
JOIN Order o ON c.ID = o.Customer_ID
GROUP BY c.ID
HAVING COUNT(*) > 2;
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>Drop the three tables.
<div class="container my-3">
<div class="row">
<div class="col-md-16 mx-auto">
<div class="pre-scrollable">
<pre>
DROP TABLE IF EXISTS Order;
DROP TABLE IF EXISTS Goods;
DROP TABLE IF EXISTS Customer;
</pre>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<div id="app"></div>
</div>
<script>
const FULL_DASH_ARRAY = 283;
const WARNING_THRESHOLD = 10;
const ALERT_THRESHOLD = 5;
const COLOR_CODES = {
info: {
color: "green"
},
warning: {
color: "orange",
threshold: WARNING_THRESHOLD
},
alert: {
color: "red",
threshold: ALERT_THRESHOLD
}
};
const TIME_LIMIT = 1800;
let timePassed = 0;
let timeLeft = TIME_LIMIT;
let timerInterval = null;
let remainingPathColor = COLOR_CODES.info.color;
document.getElementById("app").innerHTML = `
<div class="base-timer">
<svg class="base-timer__svg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<g class="base-timer__circle">
<circle class="base-timer__path-elapsed" cx="50" cy="50" r="45"></circle>
<path
id="base-timer-path-remaining"
stroke-dasharray="283"
class="base-timer__path-remaining ${remainingPathColor}"
d="
M 50, 50
m -45, 0
a 45,45 0 1,0 90,0
a 45,45 0 1,0 -90,0
"
></path>
</g>
</svg>
<span id="base-timer-label" class="base-timer__label">${formatTime(
timeLeft
)}</span>
</div>
`;
startTimer();
function onTimesUp() {
clearInterval(timerInterval);
}
function startTimer() {
timerInterval = setInterval(() => {
timePassed = timePassed += 1;
timeLeft = TIME_LIMIT - timePassed;
document.getElementById("base-timer-label").innerHTML = formatTime(
timeLeft
);
setCircleDasharray();
setRemainingPathColor(timeLeft);
if (timeLeft === 0) {
onTimesUp();
}
}, 1000);
}
function formatTime(time) {
const minutes = Math.floor(time / 60);
let seconds = time % 60;
if (seconds < 10) {
seconds = `0${seconds}`;
}
return `${minutes}:${seconds}`;
}
function setRemainingPathColor(timeLeft) {
const { alert, warning, info } = COLOR_CODES;
if (timeLeft <= alert.threshold) {
document
.getElementById("base-timer-path-remaining")
.classList.remove(warning.color);
document
.getElementById("base-timer-path-remaining")
.classList.add(alert.color);
} else if (timeLeft <= warning.threshold) {
document
.getElementById("base-timer-path-remaining")
.classList.remove(info.color);
document
.getElementById("base-timer-path-remaining")
.classList.add(warning.color);
}
}
function calculateTimeFraction() {
const rawTimeFraction = timeLeft / TIME_LIMIT;
return rawTimeFraction - (1 / TIME_LIMIT) * (1 - rawTimeFraction);
}
function setCircleDasharray() {
const circleDasharray = `${(
calculateTimeFraction() * FULL_DASH_ARRAY
).toFixed(0)} 283`;
document
.getElementById("base-timer-path-remaining")
.setAttribute("stroke-dasharray", circleDasharray);
}
</script>
</body>
</html>