forked from akwon20/CSE111_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.sql
More file actions
325 lines (277 loc) · 7.6 KB
/
queries.sql
File metadata and controls
325 lines (277 loc) · 7.6 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
-- Insert query ------------------------------------
INSERT INTO
Contains(
c_prodName,
c_cityID,
c_storeName,
c_storeNum,
c_status
)
VALUES
('The Legend of Zelda: Breath of the Wild', 1, 'Target', 1, FALSE),
('Super Mario Odyssey', 1, 'Walmart', 2, TRUE),
('Animal Crossing: New Horizons', 2, 'Target', 2, TRUE);
INSERT INTO
saleFreq(
sf_prodName,
sf_storeName,
sf_lastShipment
)
VALUES
('The Legend of Zelda: Breath of the Wild', 'Target', '2020-09-02'),
('Super Mario Odyssey', 'Walmart', '2020-08-10'),
('Animal Crossing: New Horizons', 'Target', '2020-09-28');
INSERT INTO
Store(
s_cityID,
s_storeName,
s_storeNum
)
VALUES
(1, 'Target', 1),
(1, 'Walmart', 1),
(1, 'Walmart', 2),
(1, 'Gamestop', 1),
(2, 'Target', 1),
(2, 'Target', 2),
(3, 'BestBuy', 1),
(3, 'Target', 1),
(3, 'Walmart', 1),
(3, 'Gamestop', 1)
(6, 'Amazon', 1);
INSERT INTO
products(
p_storeName,
p_prodName,
p_price,
p_releasedate,
p_type
)
VALUES
('Target','The Legend of Zelda: Breath of the Wild', 39.99, '2018-05-09', 'Software'),
('Walmart', 'Super Mario Odyssey', 49.9, '2018-10-20', 'Software'),
('Target', 'Animal Crossing: New Horizons', 59.9, '2020-05-21', 'Software')
('Target', 'Nintendo Switch with Neon Blue and Neon Red Joy-Con', 299.99, '2017-03-03', 'Hardware'),
('Target', 'Nintendo Switch with Gray Joy-Con', 299.99, '2017-03-03', 'Hardware'),
('Target', 'Nintendo Switch Lite - Turquoise', 199.99, '2019-09-20', 'Hardware'),
('Target','Nintendo Switch Lite - Gray', 199.99, '2019-09-20', 'Hardware'),
('Target', 'Nintendo Switch Lite - Yellow', 199.99, '2019-09-20', 'Hardware'),
('Target', 'Nintendo Switch Lite - Coral', 199.99, '2019-09-20', 'Hardware');
-- Hardware/software should be added dynamically when new items are added to the products table
INSERT INTO
hardware(
h_name,
h_price,
h_releaseDate
)
VALUES
('Nintendo Switch with Neon Blue and Neon Red Joy-Con', 299.99, '2017-03-03'),
('Nintendo Switch with Gray Joy-Con', 299.99, '2017-03-03'),
('Nintendo Switch Lite - Turquoise', 199.99, '2019-09-20'),
('Nintendo Switch Lite - Gray', 199.99, '2019-09-20'),
('Nintendo Switch Lite - Yellow', 199.99, '2019-09-20'),
('Nintendo Switch Lite - Coral', 199.99, '2019-09-20');
INSERT INTO
software(
s_prodName,
s_price,
s_releasedate
)
VALUES
('Animal Crossing: New Horizons', 59.9, '2020-09-28'),
('Super Mario Odyssey', 49.9, '2018-10-20'),
('The Legend of Zelda: Breath of the Wild', 39.99, '2018-05-09');
INSERT INTO
inStock(
is_prodName,
is_storeName,
is_storeNum,
is_cityID,
is_prodAmount
)
VALUES
('The Legend of Zelda: Breath of the Wild', 'Target', 1, 1, 0),
('Super Mario Odyssey', 'Walmart', 2, 1, 5),
('Animal Crossing: New Horizons', 'Target', 2, 2, 10);
INSERT INTO
shipmentETA(
sE_prodName,
sE_cityID,
sE_storeName,
sE_storeNum,
sE_lastShipment,
sE_estimatedArrival
)
VALUES
('The Legend of Zelda: Breath of the Wild', 1, 'Target', 1, '2020-09-02', '2020-09-16'),
('Super Mario Odyssey', 1, 'Walmart', 2, '2020-08-10', '2020-08-24'),
('Animal Crossing: New Horizons', 2, 'Target', 2, '2020-09-28', '2020-10-12');
INSERT INTO
locations(
l_cityID,
l_cityName
)
VALUES
(1, 'Merced'),
(2, 'Fresno'),
(3, 'Modesto'),
(4, 'Turlock'),
(5, 'Madera');
(6, 'Internet');
INSERT INTO
supplyDemand(
sD_prodName,
sD_nintendoRating,
sD_storeRatingAvg
)
VALUES
('The Legend of Zelda: Breath of the Wild', 10, 9.4),
('Super Mario Odyssey', 9.1, 9.0),
('Animal Crossing: New Horizons', 9.3, 8.8);
INSERT INTO
priceChngFreq(
pCF_prodName,
pCF_storeName,
pCF_prodStorePrice,
pCF_basePrice,
pCF_percentChng
)
VALUES
('The Legend of Zelda: Breath of the Wild', 'Target', 39.99, 49.99, -20.01),
('Super Mario Odyssey', 'Walmart', 49.99, 30.00, 40.01),
('Animal Crossing: New Horizons', 'Target', 49.99, 60.00, -17.02);
-- Search query ------------------------------------
-- Austin
-- Get full product info
SELECT *
FROM products;
-- Display stores in California
SELECT *
FROM Store;
-- Check if a specific store contains a specific product
SELECT c_storeName, c_prodName
FROM Contains
WHERE c_storeNum = 1 AND
c_prodName = 'The Legend of Zelda: Breath of the Wild' AND
c_status = 1;
SELECT c_prodName, c_storeName
SELECT p_Name
FROM inStock;
-- Check the price change frequency for a specific product
SELECT *
FROM priceChngFreq
WHERE
pCF_prodName = 'Super Mario Odyssey'
ORDER BY pCF_percentChng ASC;
-- Display only the cheapest prices from every store within a specific city
SELECT l_cityName, s_storeName, p_prodName, MIN(p_price)
FROM products, Store, locations
WHERE
s_cityID = 1
GROUP BY s_storeName
ORDER BY p_price DESC -- Must order by ascending price (Cheapest at the top)
;
-- Display only the cheapest prices from a specific store
SELECT l_cityName, s_storeName, s_storeNum, MIN(p_price)
FROM products, Store, locations
WHERE
s_cityID = 1 AND
s_storeName = 'Target'
GROUP BY s_storeNum
ORDER BY p_price DESC;
/*
-- Calculate price percentage change
SELECT pCF_percentChng
FROM priceChngFreq
WHERE
(pCF_prodStorePrice / pCF_basePrice) = pCF_percentChng;
*/
-- Delete query ------------------------------------
-- Austin
--used for deleting outdated products or unavailable items from a store's inventory
DELETE *
FROM storeInventory
WHERE
is_prodName = '' AND
is_storeName = '' AND
is_cityID = 1; -- AND
-- is_storeNum = 1 ; -- We may only need the product, store, and city
DELETE *
FROM Contains
WHERE
c_prodName = '' AND
c_storeNum = '';
DELETE *
FROM hardware;
DELETE *
FROM software;
-- Update Query -------------------------------------
-- Rodolfo
-- product info
--store does not contain product (soldout)
UPDATE
Contains
SET
c_status = 0
WHERE
c_storeName = 'Walmart' AND
c_prodName = 'Super Mario Odyssey' AND
c_cityID = 1 AND
c_storeNum = 2;
--store now contains product (restock)
UPDATE
Contains
SET
c_status = 1
WHERE
c_storeName = 'Walmart' AND
c_prodName = 'Super Mario Odyssey' AND
c_cityID = 1 AND
c_storeNum = 2;
-- product price changed (per store)
UPDATE
products
SET
p_price = 49.99
WHERE
p_storeName = 'Target' AND
p_prodName = 'Animal Crossing: New Horizons';
-- update last shipment
UPDATE
shipmentETA
SET
sE_lastShipment = '2020-11-25'
WHERE
sE_storeName = 'Target' AND
sE_prodName = 'Animal Crossing: New Horizons' AND
sE_cityID = 2 AND
sE_storeNum = 2;
-- will be updated when product is release and average of all store ratings are calculated
UPDATE
SupplyDemand
SET
sD_storeRatingAvg = '8.9'
WHERE
sD_prodName = 'Super Mario Odyssey';
-- ratings
UPDATE
SupplyDemand
SET
sD_storeRatingAvg = 8.5
WHERE
sD_prodName = ''; --may need to added store name to relation table to carry out this operation
--price anaysis (one of our use cases)
UPDATE
priceChngFreq
SET
pCF_basePrice = 59.9 --when base price of product changes(offical nintendo store price)
WHERE
pCF_prodName = 'Animal Crossing: New Horizons';
--need to account for opperation to calculate pCF_percentChng with consideration to base price and individual store prices
UPDATE
priceChngFreq
SET
pCF_percentChng = -16.66
WHERE
pCF_prodName = 'Animal Crossing: New Horizons' AND
pCF_storeName = 'Target';