Lab 7
Lab 7
Receipts
ReceiptNumber : unique identifier of the receipt
Date : date of the purchase. The date is in DD-MM-YYY format,
CustomerId : id of the customer (see customers.Id)
Summary of Bakery database:
CUSTOMERS (cid , fname, lname)
PRODUCTS (pid, flavor, food, price)
RECEIPTS (rno, rdate, cid)
ITEM_LIST (rno, ordinal, item)
● Understand the database.
● Draw schema diagram for Bakery database.
● Create relations with appropriate data types and integrity constraints.
● Populate the database values using the Bakery.sql file.
Exercise :
Write the following using Sub-query:
1. Display the food details that is not purchased by any of customers.
2. Show the customer details who had placed more than 2 orders on the same date.
3. Display the products details that has been ordered maximum by the customers.
(use ALL)
4. Show the number of receipts that contain the product whose price is more than
the average price of its food type.
Write the following using JOIN: (Use sub-query if required)
5. Display the customer details along with receipt number and date for the receipts
that are dated on the last day of the receipt month.
6. Display the receipt number(s) and its total price for the receipt(s) that contain
Twist as one among five items. Include only the receipts with total price more than
$25.
7. Display the details (customer details, receipt number, item) for the product that
was purchased by the least number of customers.
8. Display the customer details along with the receipt number who ordered all the
flavors of Meringue in the same receipt.
Write the following using Set Operations:
9. Display the product details of both Pie and Bear Claw.
10.Display the customers details who haven't placed any orders.
11. Display the food that has the same flavor as that of the common flavor between
the Meringue and Tart.
12. Create a view named Blue_Flavor, which display the product details (product
id, food, price) of Blueberry flavor.
13. Create a view named Cheap_Food, which display the details (product id,
flavor, food, price) of products with price lesser than $1. Ensure that, the price of
these food(s) should never rise above $1 through view.
14. Create a view called Hot_Food that show the product id and its quantity where
the same product is ordered more than once in the same receipt.
15. Create a view named Pie_Food that will display the details (customer lname,
flavor, receipt number and date, ordinal) who had ordered the Pie food with receipt
details.
16. Create a view Cheap_View from Cheap_Food that shows only the product id,
flavor and food.
Note: Read the questions carefully and then create database accordingly.