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

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

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

with info as
(
SELECT pi.product_id,ov.order_id,in_price,price,cnt
    FROM tb_product_info pi INNER JOIN
    tb_order_detail od ON
    pi.product_id = od.product_id
    INNER JOIN tb_order_overall ov ON
    ov.order_id = od.order_id
    WHERE date(event_time) >= "2021-10-01"
    AND shop_id = 901
)

select '店铺汇总' as product_id,
    concat( round(( 1 - sum(in_price*cnt) / sum(price * cnt) )*100, 1), '%')
from info
union all
select product_id,
    concat( round(( 1 - max(in_price) / (sum(price * cnt)/ sum(cnt)) )*100, 1), '%')
from info
where product_id in
    (
        select product_id
        from info
        group by product_id
        having ( 1 - max(in_price) / (sum(price * cnt)/ sum(cnt)) )*100 > 24.9
    )
GROUP BY product_id

全部评论

相关推荐

AAA不喝拿铁:西电本硕学历没问题,但是项目名字首先得改虽然一眼能看出来是点评但是不能演都不演就直接给面试官端上去。技术点全是redis显得这像redis的课程实验,也要改。我根据真实面经整理得到的最全(高/中/低频)面试题,需要的牛u可以订阅一手我的专栏,祝好运
点赞 评论 收藏
分享
待现的未见之事:起码第一句要把自己的优势说出来吧。比如什么xx本27届学生,随时到岗....
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务