题解 | 了解 2023 年全年所有商品的盈利情况

了解 2023 年全年所有商品的盈利情况

https://www.nowcoder.com/practice/05cbbb8662c14b46a15cbcb8993d9277

select s.product_id,sum((unit_price-purchase_price)*quantity) as total_profit,
 round(avg((unit_price-purchase_price))/purchase_price*100,2) as profit_margin
from sales_orders s
join purchase_prices p on p.product_id=s.product_id
where order_date >= '2023-01-01' AND order_date <= '2023-12-31'
group by s.product_id
order by s.product_id;

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务