with s as(
 select product_id,sum(quantity) as s_quantity
 from sales_underline
 where year(sale_date)=2024
 group by product_id),
r as(
 select product_id,avg(rating) as rat
 from reviews_underline
 group by product_id
 having avg(rating)<4)
select p.product_id as product_id,
 p.product_name as product_name,
 s_quantity as total_quantity,
 round(rat,2) as average_rating
 from products_underline p join s on p.product_id=s.product_id
 join r on p.product_id=r.product_id
 group by p.product_id,p.product_name
 order by average_rating,product_id