Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Stores( store_id: integer, name: String, address: string ) Items( item name: Str

ID: 3736904 • Letter: S

Question

Stores( store_id: integer, name: String, address: string ) Items( item name: String, weight: real, color: String ) Inventory( store id: integer, item name: String, price: real) 2. [8 pts] Provide the SQL that will execute these queries. Find the names of stores that have every item in their inventory. Find all pairs of store ids such that the store with the first id charges more for an item than the second store (second id) charges for the same item. Find the ids and names of all stores which have at least one green and at least one red item in inventory. For every store whose inventory contains at least one green item and at least red item, print the name and price of the most expensive item in the store. a. b. c. d.

Explanation / Answer

Give me a comment, if you get any error...

a) SELECT S.name
FROM Stores S
WHERE NOT EXISTS (SELECT It.item_name
FROM Items It
WHERE NOT EXISTS (SELECT I.store_id
FROM Inventory I
WHERE I.store_id = S.store_id AND It.item_name = I.item_name));


b) SELECT I1.store_id, I2.store_id
FROM Inventory I1, Inventory I2
WHERE I1.item_name = I2.item_name AND I1.store_id
<> I2.store_id AND I1.price > I2.price


c) SELECT S.store_id, S.name
FROM Stores S, Inventory I, Items It
WHERE S.store_id = I.store_id AND I.item_name = It.item_name AND It.color='green' AND S.store_id IN(

SELECT S1.store_id
FROM Stores S1, Inventory I1, Items It1
WHERE S1.store_id = I1.store_id AND I1.item_name = It1.item_name AND It1.color='red');

d)

SELECT I2.item_name, MAX(I2.price)

FROM Inventory I2
WHERE I.store_id IN(
SELECT S.store_id
FROM Stores S, Inventory I, Items It
WHERE S.store_id = I.store_id AND I.item_name = It.item_name AND It.color='green' AND S.store_id IN(SELECT S1.store_id
FROM Stores S1, Inventory I1, Items It1
WHERE S1.store_id = I1.store_id AND I1.item_name = It1.item_name AND It1.color='red')
)
GROUP BY I2.item_name;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote