data manipulation efficiency and complex logical filtering

PHOTO EMBED

Thu Apr 09 2026 15:08:37 GMT+0000 (Coordinated Universal Time)

Saved by @yasvanthM

SELECT 
    DATE_TRUNC('month', submit_date) AS mth, 
    p.product_name AS product, 
    ROUND(AVG(stars), 2) AS avg_stars
FROM reviews r
JOIN products p ON p.product_id = r.product_id
GROUP BY mth, product
ORDER BY mth ASC, product ASC;
content_copyCOPY

Question 1: Average Monthly Rating (Product Performance) The Scenario: IBM wants to track the monthly satisfaction levels for various products. You are given a products table and a reviews table. Task: Write a query to find the average rating for each product per month. Round the results to two decimal places. Key Challenge: Correctly grouping by a truncated date (month/year) and a product name simultaneously.