Conditions:
3 distinct pizzas, total price <=$80,
Each pizza must be liked by at least 1 of customer (A/B/C). A,B,C are fixed requirements
(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 |
| A | Pizza3 |
| A | Pepperoni |
| B | Pizza3 |
| B | Hawaiian |
| C | Hawaiian |
| D | Pizza4 |
The 3 possible pizzas would be Hawaiian, Pizza3 and Pepperoni.
So A must like at least Hawaiian & Pizza3. B must like at least Pizza3 & Hawaiian while C must like at least 2/3 of the pizza which is Pepperoni and Hawaiian.
A & B & C need not like the same pizza. But each pizza must be like by at least 1 customer.
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
AND 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 (A/B/C).
(A & B & C) must like at least 2 of the 3 pizzas
Reference for database schema: http://sqlfiddle.com/#!9/dceae9/1