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

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

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

with t as (
    select product_id, price, in_price,
    case
        when status=1 then cnt
        when status=2 then cnt*-1
        when status=0 then 0
    end as cnt
    from (
    select t1.product_id, price, cnt, status, in_price
    from tb_order_detail t1
    join tb_order_overall t2
    join tb_product_info t3
    on t1.order_id=t2.order_id and t1.product_id=t3.product_id
    where date(event_time)>='2021-10-01' and shop_id=901 
    ) t4
)

(select '店铺汇总' as product_id,
    concat(round((1-sum(in_price*cnt)/sum(price*cnt))*100, 1), '%') as profit_rate
from t)
union
(select product_id,
    concat(round((1-sum(in_price*cnt)/sum(price*cnt))*100, 1), '%') as profit_rate
from t
group by product_id
having (1-sum(in_price*cnt)/sum(price*cnt))>0.249
order by product_id);

全部评论

相关推荐

卡bg这么严,不是92真是太难了
投递芯原微电子(上海)股份有限公司等公司10个岗位
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
球球别拷打俺了:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
08-09 12:00
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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