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

3. Create a view named order_item_products that returns columns from the Orders,

ID: 3719954 • Letter: 3

Question

3. Create a view named order_item_products that returns columns from the Orders, Order_Items, and Products tables. This view should return these columns from the Orders table: order_id, order_date, tax_amount, and ship_date. This view should return these columns from the Order_Items table: item_price, discount_amount, final_price (the discount amount subtracted from the item price), quantity, and item_total (the calculated total for the item). This view should return the product_name column from the Products table. 4. Create a view named product_summary that uses the view you created in exercise 4. This view should return summary information about each product. Each row should include product_name, order_count (the number of times the product has been ordered) and order_total (the total sales for the product). 5. Write a SELECT statement that uses the view that you created in exercise 5 to get total sales for the five best selling products.

Explanation / Answer

Answer for question 3:

CREATE VIEW order_item_products AS
SELECT
o.order_id,
o.order_date,
o.tax_amount,
o.ship_date,
oi.item_price,
oi.discount_amount,
oi.quantity,
(oi.item_price - oi.discount_amount) AS actual_price,
((oi.item_price - oi.discount_amount) * oi.quantity) AS final_price,
p.product_name
FROM orders AS o
JOIN order_items AS oi
ON o.order_id = oi.order_id
JOIN products AS p
ON p.product_id = oi.product_ID
;

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