# 每个人在2024年7月的总收入 按照id排列
with
t1 as(
    select
        courier_id,
        sum(delivery_fee) as dcount
    from
        deliveries_info
    where
        delivery_date between '2024-07-01' and '2024-07-31'
    group by
        courier_id
)
,
t2 as(
    select
        courier_id,
        courier_name,
        base_salary+dcount as total_income
    from
        couriers_info left join t1 using(courier_id)
    order by
        courier_id
)

select * from t2