leetcode 1251. 平均售价

95 阅读1分钟

1251. 平均售价 - 力扣(LeetCode)

逐步调试 + 分析 + 蛋疼的数据

select
    p.product_id,
    ifnull (round(sum(u.units * p.price) / sum(u.units), 2), 0) as average_price
from
    Prices as p
left join
    UnitsSold u
on
    p.product_id = u.product_id
    and
    u.purchase_date >= p.start_date and u.purchase_date <= p.end_date
group by p.product_id;