Problem Statement
You need average rating per product, but some rows have NULL rating. What does AVG(rating) return?
Explanation
AVG ignores NULL values. Only present ratings contribute to the average.
Use COALESCE when you want to substitute a default before aggregation.
Code Solution
SolutionRead Only
SELECT product_id, AVG(rating) AS avg_rating FROM reviews GROUP BY product_id;
Practice Sets
This question appears in the following practice sets:
