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

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

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

with product_rate as (

    select product_id, concat(round(profit_rate * 100,1), '%') as profit_rate
    from
    (select t1.product_id, round((1-in_price/average_price), 3) as profit_rate
    from
    (select product_id, sum(price*cnt)/sum(cnt) as average_price
    from tb_order_detail left join tb_order_overall on tb_order_detail.order_id = tb_order_overall.order_id
    where event_time >='2021-10-01'
    group by product_id) as t1 join tb_product_info on t1.product_id = tb_product_info.product_id
    where shop_id = 901
    having profit_rate > 0.249
    order by t1.product_id) as t5
    
), 
store as(
    select product_id, concat(round(profit_rate*100,1), '%') as profit_rate
    from
    (select '店铺汇总' as product_id, round((1-sum(cost)/sum(revenue)),3) as profit_rate
    from
    (select t2.product_id, in_price*cnt as cost, price*cnt as revenue
    from
    (select product_id, price, cnt
    from tb_order_overall right join tb_order_detail on tb_order_overall.order_id = tb_order_detail.order_id
    where event_time >='2021-10-01 ' and status != 2) as t2 left join tb_product_info on t2.product_id = tb_product_info.product_id
    where shop_id = 901
) as t3) as t6
)

select product_id, profit_rate
from store
union
select product_id, profit_rate
from product_rate

全部评论

相关推荐

小鹏、大疆、米哈游、MinMax小鹏上午投的下午就约面,进度未免也太快了
蛇年行大运fff:哥们 盗贴有意思吗,我发xhs上的给你搬过来了😅😅😅
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
05-25 10:45
门头沟学院 Java
Frank_zhan...:没实习一个项目肯定不够,可以再做一个轮子,技术栈再补一个mq,微服务,整体再换个简历模板,暑期尽量再找一个日常实习
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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