题解 | 了解 2023 年全年所有商品的盈利情况
了解 2023 年全年所有商品的盈利情况
https://www.nowcoder.com/practice/05cbbb8662c14b46a15cbcb8993d9277
select
product_id,
sum((unit_price - purchase_price) * quantity) as total_profit,
round(
100 * (avg(unit_price) - purchase_price) / purchase_price,
2
) as profit_margin
from
purchase_prices
join sales_orders using (product_id)
where
order_date between '2023-01-01' and '2023-12-31'
group by
product_id
order by
product_id
查看6道真题和解析