题解 | 电商平台需要对商家的销售业绩、退款情况和客户满意度进行综合评估

电商平台需要对商家的销售业绩、退款情况和客户满意度进行综合评估

https://www.nowcoder.com/practice/48a236567617449eb6010274b30b29e8

关键:进行子查询后连接,避免原表连接导致笛卡尔积膨胀。

select m.merchant_id merchant_id,merchant_name,total_sales_amount,total_refund_amount,average_satisfaction_score
from merchants_underline m
left join (
    select merchant_id,sum(sale_amount) total_sales_amount
    from sales_underline
    group by merchant_id
) s on m.merchant_id=s.merchant_id
left join (
    select merchant_id,sum(refund_amount) total_refund_amount
    from refunds_underline
    group by merchant_id
) r on m.merchant_id=r.merchant_id
left join (
    select merchant_id,round(avg(satisfaction_score),2) average_satisfaction_score
    from satisfaction_underline
    group by merchant_id
) sa on m.merchant_id=sa.merchant_id
order by merchant_id

全部评论

相关推荐

头像
2025-12-16 14:57
门头沟学院 Java
迷茫的大四🐶:是这样的,我都拿到你这同一水平的offer了,那我接你的offer的意义在哪,我一开始想接你们的offer期待是很高的,希望你们下次继续努力
你今年的保底offer是...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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