leetcode 1251 平均售價

leetcode 1251 平均售價

select r.product_id, round(sum(r.price * r.units) / sum(r.units), 2) as average_price 
from (
    select p.product_id, p.price , u.units from Prices p
    left join UnitsSold u 
    on p.product_id = u.product_id 
    where u.purchase_date between p.start_date and p.end_date
) r
group by r.product_id

==

posted @ 2023-05-12 12:32  Carl_ZhangJH  阅读(15)  评论(0)    收藏  举报