Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Get Minimum Price by Category | Section
Intermediate SQL

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!

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  17
single

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.name column and the minimum value of the price column from the tables.
  • Assign the alias category_name to the first column and min_price to the second.
  • Join the product table on the common column category.id = product.category_id.
  • Group the data by category.name.
  • Use a HAVING clause with the condition COUNT(DISTINCT product.id) > 5 to count unique products per category.
  • Sort the results by category_name.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  17
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt