MYSQL VIEW QUERY Hi, I need some help with some mysql view queries, any help wou
ID: 3916694 • Letter: M
Question
MYSQL VIEW QUERY
Hi, I need some help with some mysql view queries, any help would be greatly appreciated!
Create a view named product_summary. This view should return summary information
about each product. Each row should include product_id, order_count (the number of times the
product has been ordered) and order_total (the total sales for the product). Write a SELECT
statement that returns all the columns from the product_summary view.
Create a view named order_items that returns columns from the ORDERS, ORDERITEMS,
and PRODUCT 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
ORDERITEMS 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 PRODUCT Table.
Write a SELECT statement that returns all the columns from the order_items view.
Explanation / Answer
Create view product_summary as Select Product.product_id,count(order_id) as order_count ,sum(quantity*item_price) as order_total from Product inner join OrderItems on Product.product_id = OrderItems.product_id group by Product.product_id;
Select * from product_summary;
Create view order_items as Select Orders.order_id, order_date,tax_amount, ship_date , OrderItems.item_price, discount_amount, (item_price - discount_amount) as final_price , quantity, item_price * quantity as item_total ,product_name from Product inner join OrderItems on Product.product_id = OrderItems.product_id inner join Orders on Orders.order_id = OrderItems.order_id;
Select * from order_items;
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.