题解 | 三表连接

三表连接

https://www.nowcoder.com/practice/c86c980ce4544959b4691448c937620e

select
    c.商品类型,
    sum(a.支付金额) as 支付金额,
    sum(b.总运费) as 总运费,
    sum(b.总运费) / sum(a.支付金额) as 运费占比
from
    订单表 a 
left join 
    运费表 b on a.订单号 = b.订单号
left join
    品类表 c on a.商品号 = c.商品号 and b.商品号 = c.商品号
where 
    c.商品类型 is not null
group by 
    1

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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