Challenge: Get Minimum Price by Category
The company needs to find the minimum price of a product from each category in order to organize a marketing campaign. They have assigned you this task!
フィードバックありがとうございます!
single
Challenge: Get Minimum Price by Category
メニューを表示するにはスワイプしてください
The company needs to find the minimum price of a product from each category in order to organize a marketing campaign. They have assigned you this task!
スワイプしてコーディングを開始
Your task is to obtain the minimum price for each product category. However, to provide customers with options, you need to retrieve only those categories where there are more than 5 distinct products.
You should count the number of different products in each category using COUNT(DISTINCT product.id) in your HAVING clause. This ensures you are counting unique products, not just the total number of product rows (which could include duplicates).
Join two tables, aggregate the data, and use the HAVING clause with COUNT(DISTINCT product.id) > 5.
At the end, sort the result by the category_name in ascending order.
Pay attention that in the response, you should have 2 columns: category_name and min_price. So don't forget to set aliases for these columns!
Brief Instructions
- Retrieve the
category.namecolumn and the minimum value of thepricecolumn from the tables. - Assign the alias
category_nameto the first column andmin_priceto the second. - Join the
producttable on the common columncategory.id = product.category_id. - Group the data by
category.name. - Use a
HAVINGclause with the conditionCOUNT(DISTINCT product.id) > 5to count unique products per category. - Sort the results by
category_name.
解答
フィードバックありがとうございます!
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください