Chapter 4 · Aggregations
57. Product Rating Breakdown with CASE
Medium20 XPE-Commerce
For each product, calculate the number of positive reviews (rating >= 4), neutral reviews (rating = 3), and negative reviews (rating <= 2). Return product_id and the three counts. Only include products with at least 2 reviews total. Sort by product_id.
Tables
- PKidINT
- FKproduct_id→ products.idINT
- FKcustomer_id→ customers.idINT
- ratingINT
- commentTEXT
- review_dateTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.