题解 | #某店铺的各商品毛利率及店铺整体毛利率#

某店铺的各商品毛利率及店铺整体毛利率

https://www.nowcoder.com/practice/65de67f666414c0e8f9a34c08d4a8ba6

SELECT 
    '店铺汇总' AS product_id,
    CONCAT(ROUND((1 - SUM(in_price*cnt) / SUM(price*cnt))*100, 1), '%') AS profit_rate
FROM tb_order_detail t3
JOIN tb_order_overall t2 ON t3.order_id = t2.order_id
JOIN tb_product_info t1 ON t3.product_id = t1.product_id
WHERE shop_id = 901 AND event_time > '2021-10-01'

UNION 

SELECT
    t3.product_id,
    CONCAT(ROUND((1 - SUM(in_price*cnt) / SUM(price*cnt))*100, 1), '%') AS profit_rate
FROM tb_order_detail t3
JOIN tb_order_overall t2 ON t3.order_id = t2.order_id
JOIN tb_product_info t1 ON t3.product_id = t1.product_id
WHERE shop_id = 901 AND event_time > '2021-10-01'
GROUP BY product_id
HAVING ROUND((1 - SUM(in_price*cnt) / SUM(price*cnt))*100, 1) > 24.9

分别查询得到店铺汇总的毛利率和各商品的毛利率,再使用UNION函数将其合并。

全部评论

相关推荐

整顿职场的柯基很威猛:这种不可怕,最可怕的是夹在一帮名校里的二本选手,人家才是最稳的。
点赞 评论 收藏
分享
牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务