Conditions:
-
3 distinct pizzas, total price <=$ 80,
-
Each pizza must be liked by at least 1 of customer (A/B/C)
-
(A & B & C) must like at least 2 of the 3 selected pizzas
Expected Results: List with (Restaurant name, pizza1,pizza2,pizza3, Total cost)
Database schema: Customers(cname, area), Restaurants(rname, area), Pizzas(pizza), Sells(rname,pizza,price), Likes(cname, pizza)
Sells table
| rname | Pizzas | Price | ------------------------------ | rname1 | Hawaiian | $ 10 | | rname2 | Pepperoni | $ 20 | | rname2 | Pizza3 | $ 20 | | rname3 | Pizza4 | $ 20 |
Likes table
| cname | Pizzas ---------------------- | A | Hawaiian | | B | Pizza3 | | C | Pepperoni | | D | Pizza4 |
SQL Query:
SELECT s1.rname, s1.pizza, s2.pizza, s3.pizza, (s1.price+s2.price+s3.price) FROM Sells s1 join Sells s2 join Sells s3 ON s1.rname = s2.rname = s3. rname -- is this allowed? s1.price < s2.price < s3.price WHERE s1.pizza < s2.pizza < s3.pizza
Issue: I still need to add the likes table into the query to check
-
Each pizza must be liked by at least 1 of customer (A/B/C)
-
(A & B & C) must like at least 2 of the 3 pizzas
-
Not too sure what the title should be