QUESTION

Text
Image


A department store maintains data on customers, products, and purchase records in three tables: CUSTOMER, PRODUCT, and PURCHASE. The store manager wants to find the average price of all distinct products that are purchased within a category for each category. Write a query to print category and the average of price minus discount for the distinct products that are purchased in the category for each category. Vchema \begin{tabular}{|c|c|l|} \hline \multicolumn{2}{|l|}{ CUSTOMER } \\ \hline Name & Type & \multicolumn{1}{|c|}{ Description } \\ \hline ID & Integer & A customer's ID in the inclusive range [1, 500]. This is a primary key. \\ \hline NAME & String & A customer's name. This field contains between 1 and 100 characters (inclusive). \\ \hline CITY & String & A city name. This field contains between 1 and 50 characters (inclusive). \\ \hline STATE & String & A state name. This field contains between 1 and 50 characters (inclusive). \\ \hline \end{tabular}


\begin{tabular}{|c|c|c|} \hline \multicolumn{2}{|l|}{ PRODUCT } \\ \hline Name & Type & \\ \hline ID & Integer & A product's ID in the inclusive range [1, 500]. This is a primary key. \\ \hline NAME & String & A product's name. This field contains between 1 and 50 characters (inclusive). \\ \hline CATEGORY & String & A category name of the product. This field contains between 1 and 50 characters (inclusive). \\ \hline PRICE & Integer & The price of the product in the inclusive range [500, 1000]. \\ \hline DISCOUNT & Integer & The discount associated with the product in the inclusive range [5, 20]. \\ \hline AVAILABLE & Integer & The availability of a product. It is 1 if the product is available or it is 0 if the product is not available. \\ \hline \end{tabular} \begin{tabular}{|c|c|l|} \hline \multicolumn{2}{|l|}{ PURCHASE } \\ \hline Name & Type & \\ \hline ID & Integer & An id associated with a purchase that is done in the inclusive range [1, 1000]. This is a primary key. \\ \hline CUSTOMER_ID & Integer & A customer ID. This is a foreign key to customer.customer_id. \\ \hline PRODUCT_ID & Integer & A product ID. This is a foreign key to product.product_id. \\ \hline PURCHASE_DATE & Date & The date associated with a purchase. The date falls in the range '2000-01-01' to '2000-12-31' (inclusive). \\ \hline \end{tabular}MYSQL

Public Answer

NKTVMZ The First Answerer