For this assignment, we will be using the following relational schema for our qu
ID: 3903681 • Letter: F
Question
For this assignment, we will be using the following relational schema for our queries.
Customer(CID, Name, Address)
Orders(Ordernum, CID, Order_date, Cardnum)
Orderlist(Ordernum, ISBN, Qty, Ship_date)
Book(ISBN, Title, Author, Qty_in_stock, Price)
When an order is placed, there is one entry added to Orders which contains the customer information and order details. Then there is one entry per book entered into Orderlist with "NULL" in the ship date which will be replaced once that line item has been shipped. Each book item will only be shipped when all the copies are present (ie: we have sufficient Qty_in_stock for the Qty of the order, that way there is a unique ship_date for each line item). Note: you can also take advantage of renaming (RA) and views (SQL) to break down some of the queries into smaller parts.
SQL Queries
12. Write a SQL QUERY which will list the customer name, order number and total value for any order which had more than 10 books ordered on it.
If you write a Relational Algebra Query, I will downvote.
Thank you.
Explanation / Answer
CREATE VIEW order_qty_amount AS SELECT orderlist.Ordernum, SUM(orderlist.Qty) as bookQuantity, SUM(book.Price*orderlist.Qty) as totalCost FROM orderlist
LEFT JOIN book ON orderlist.ISBN=book.ISBN
GROUP BY orderlist.Ordernum ORDER BY SUM(orderlist.Qty)
SELECT customer.Name, order_qty_amount.totalCost FROM order_qty_amount LEFT JOIN orders ON order_qty_amount.Ordernum=orders.Ordernum
LEFT JOIN customer ON orders.CID=customer.CID WHERE order_qty_amount.bookQuantity > 10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.