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

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

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

with a as(
select
    D.order_id,
    I.product_id,
    in_price,
    D.price,
    D.cnt
from
    tb_order_detail as D 
join tb_order_overall as O
on O.order_id = D.order_id
join tb_product_info as I
on I.product_id = D.product_id
where
    event_time >= '2021-10-01' and shop_id = 901
),
b as (
select
    product_id,
    sum(in_price*cnt) as total_in,
    sum(price*cnt) as total_amount,
    round((1-sum(in_price*cnt)/sum(price*cnt)) * 100, 1) as profit_rate
from
    a
group by
    product_id
)
select
    '店铺汇总' as product_id,
    concat(round((1-sum(total_in)/sum(total_amount)) * 100, 1), '%') as profit_rate
from
    b
union
select
    product_id,
    concat(profit_rate, '%') as profit_rate
from
    b
where
    profit_rate > 24.9

这店铺汇总算了我半天,后面看别人题解才知道要把小于24.9%的也算进店铺里

全部评论

相关推荐

02-07 10:52
复旦大学 Java
混子不想混:非常能理解,感觉他们就靠着入行早,打压新人一样。我这个公司也是,天天干的累死累活,然后绩效打C,合着让新人被绩效,像是年底攒棺材本一样。总是打击之后,还会让人开始自我怀疑,是不是我努力的还不够,实际上并不是,就是他们不做人,故意打压新人。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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