Problem
E-commerce platforms surface product ratings to help shoppers make informed decisions. Before promoting items on the homepage, the product team runs this query to identify which products customers love most and how much review data backs up each score. A product with a 5-star average from a single review is treated differently than one averaging 4.8 stars from hundreds. Using the reviews table, return product_id, avg_rating (rounded to 2 decimal places), and review_count, ordered by avg_rating descending.
Schema
reviews
| column | type |
|---|
| id | INTEGER |
| product_id | INTEGER |
| user_id | INTEGER |
| rating | INTEGER |
| created_at | DATE |
Sample Data
| id | product_id | user_id | rating |
|---|
| 1 | 1 | 101 | 5 |
| 2 | 1 | 102 | 4 |
| 3 | 2 | 103 | 3 |
| 4 | 2 | 104 | 2 |
| 5 | 3 | 105 | 5 |
Expected Output
| product_id | avg_rating | review_count |
|---|
| 3 | 5.00 | 1 |
| 1 | 4.50 | 2 |
| 2 | 2.50 | 2 |