89.6k views
1 vote
Create a view named product_summary that uses the view you created in question 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).

1 Answer

4 votes

Answer:

Following are the Query to this question:

/*creating view product_summary */

CREATE VIEW product_summary AS

SELECT product_name, COUNT (order id) As order_count,

/* selects columns names */

SUM(item_total) AS order_total /* add values */

FROM order_item_products /* table name order_item_products*/

GROUP BY product name;

Step-by-step explanation:

Creating view description can be described as follows:

  • In view creation "CREATE VIEW' command is used, which creates its view "product_summary".
  • In this creation, the columns are used, which returns the view that will come from the "SELECT" command.
  • In this "FROM" command is uses the table, in which all "order_count" and "order_total" manipulate columns, use the "AS" command is used, which gives all the existing values, and it also uses the group by, which operates each product.
User Olyanren
by
4.6k points