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

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

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

刚开始忽略了having round(100 * (1 - SUM(in_price*cnt) / SUM(price*cnt)),1)>24.9 or product_id is null 中product_id is null 这个条件,一直通过不了。后来想到having在select前执行,又使用了with Rollup 会出现一个null 值,如果只判定>24.9就把null值过滤掉了,所以这个条件必须加。还有个有些人可能会忽略的问题,判定>24.9要用数值去比,不能直接having profit_rate>'24.9%'
select 
    ifnull(c.product_id,'店铺汇总')product_id,
    concat(round(100 * (1 - SUM(in_price*cnt) / SUM(price*cnt)),1),'%')as profit_rate
from tb_order_overall a 
inner join tb_order_detail b on a.order_id=b.order_id
inner join tb_product_info c on  b.product_id=c.product_id
where date_format(event_time,'%Y-%m')>='2021-10' and shop_id='901'
group by c.product_id 
with rollup
having round(100 * (1 - SUM(in_price*cnt) / SUM(price*cnt)),1)>24.9 or product_id is null
order by c.product_id 

#TPLINK秋招提前批#
全部评论

相关推荐

04-17 10:16
门头沟学院 Java
小浪_coder:24届很难找了,马上25的都毕业了还有很多没找到的
点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q了:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务