题解 | 物流公司想要分析快递小哥的薪资构成和绩效情况

物流公司想要分析快递小哥的薪资构成和绩效情况

https://www.nowcoder.com/practice/4be55ba954bf4f928a2d6ff840f23d1b

with
    t1 as (
        select distinct
            courier_id,
            courier_name,
            sum(delivery_fee) over (
                partition by
                    courier_id
            ) as add_fee
        from
            couriers_info
            left join deliveries_info using (courier_id)
        where
            date_format(delivery_date, "%Y-%m") = '2024-07'
    ) ,t2 as (
        select distinct
            courier_id,
            courier_name,
            base_salary - sum(expense_amount) over (
                partition by
                    courier_id
            ) as jian_fee
        from
            couriers_info
            left join expenses_info using (courier_id)
        where
            date_format(expense_date, "%Y-%m") = '2024-07'
    )
select
    t2.courier_id,
    t2.courier_name,
    jian_fee + add_fee as total_income
from
    t2
    left join t1 using (courier_id)

全部评论

相关推荐

10-20 11:11
辽宁大学 营销
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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