select a.product_id, product_name, 
qty as total_quantity,
round(avg(rating), 2) as average_rating
from products_underline a
join (
    select product_id, sum(quantity) as qty
    from sales_underline
    where year(sale_date)=2024
    group by product_id
) b on a.product_id=b.product_id
join reviews_underline c on b.product_id=c.product_id
group by a.product_id, product_name
having average_rating<4
order by average_rating, a.product_id