Bird
Raised Fist0

If a review system stores reviews in a SQL table with columns (user_id, product_id, rating, review_text), which SQL query retrieves the average rating for product_id = 101?

medium📝 Analysis Q5 of Q15
LLD - Design — Food Delivery System
If a review system stores reviews in a SQL table with columns (user_id, product_id, rating, review_text), which SQL query retrieves the average rating for product_id = 101?
ASELECT rating FROM reviews WHERE user_id = 101;
BSELECT AVG(rating) FROM reviews WHERE product_id = 101;
CSELECT COUNT(rating) FROM reviews WHERE product_id = 101;
DSELECT * FROM reviews WHERE rating > 101;
Step-by-Step Solution
Solution:
  1. Step 1: Identify the goal

    We want the average rating for product 101.
  2. Step 2: Choose SQL aggregate function

    AVG(rating) calculates average rating; filter by product_id = 101.
  3. Final Answer:

    SELECT AVG(rating) FROM reviews WHERE product_id = 101; -> Option B
  4. Quick Check:

    Average rating query = SELECT AVG(rating) [OK]
Quick Trick: Use AVG() with WHERE for product filtering [OK]
Common Mistakes:
MISTAKES
  • Using COUNT instead of AVG
  • Filtering by user_id instead of product_id
  • Selecting all reviews without aggregation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes