select t2.*, IFNULL(t3.fee_supplier,0) as order_fee_supplier, IFNULL(t3.fee_partner,0) as order_fee_partner, IFNULL(t3.fee_platform,0) as order_fee_platform, IFNULL(t3.fee_platform_pack,0) as order_fee_platform_pack, IFNULL(t3.fee_platform_check,0) as order_fee_platform_check, IFNULL(t3.fee_platform_transport,0) as order_fee_platform_transport, IFNULL(t3.total_fee,0) as order_total_fee, IFNULL(t3.fee_packing_transport,0) as order_fee_packing_transport from ( select t1.order_id,sum(t1.num) as order_num , sum(t1.total) as order_total, sum(t1.supplier_price_amount) as order_supplier_price_amount, sum(t1.markup_one_amount) as order_markup_one_amount,sum(t1.markup_two_amount) as order_markup_two_amount, sum(t1.markup_partner_amount) as order_markup_partner_amount,sum(t1.price_amount) as order_price_amount,sum(t1.original_price_amount) as order_original_price_amount,sum(t1.price_discount_amount) as order_price_discount_amount,sum(t1.coupon_amount_total) as order_coupon_amount_total,sum(t1.check_fee) as order_check_fee,sum(t1.lack_fee_supplier) as order_lack_fee_supplier,sum(t1.replace_fee) as order_replace_fee, sum(replace_num) as order_replace_num,sum(reduce_num) as order_reduce_num,sum(lack_num) as order_lack_num from ( SELECT oi.order_id, oi.id, IFNULL(oi.num,0) as num, IFNULL(oi.total,0) as total, IFNULL(oi.supplier_price,0) as supplier_price, IFNULL(oi.supplier_price,0) * IFNULL(oi.num,0) as supplier_price_amount, IFNULL(oi.markup_one,0) as markup_one, IFNULL(oi.markup_one,0)* IFNULL(oi.num,0) as markup_one_amount, IFNULL(oi.markup_two,0) as markup_two, IFNULL(oi.markup_two,0)* IFNULL(oi.num,0) as markup_two_amount, IFNULL(oi.markup_partner,0) as markup_partner, IFNULL(oi.markup_partner,0)* IFNULL(oi.num,0) as markup_partner_amount, IFNULL(oi.price,0) as price, IFNULL(oi.price,0)* IFNULL(oi.num,0) as price_amount, IFNULL(oi.original_price,0) as original_price, IFNULL(oi.original_price,0)*IFNULL(oi.num,0) as original_price_amount, IFNULL(oi.original_price,0)*IFNULL(oi.num,0) - IFNULL(oi.price,0)* IFNULL(oi.num,0) as price_discount_amount, IFNULL(oi.real_price,0) as real_price, IFNULL(oi.real_total,0) as real_total, IFNULL(oi.coupon_amount_total,0) as coupon_amount_total, IFNULL(ois.check_fee,0) as check_fee, IFNULL(ois.lack_fee_supplier,0) as lack_fee_supplier, IFNULL(ois.replace_fee,0) as replace_fee ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace'),0) as replace_num ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce'),0) as reduce_num ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack'),0) as lack_num FROM t_order o left join t_order_item oi on oi.order_id=o.id left join t_station s on s.id = oi.station_id left join t_supplier_info si on si.id = oi.supplier_id left join t_order_item_settlement ois on ois.order_item_id = oi.id WHERE oi.deleted = 0 and o.payment_time > #{dto.startDate} and o.payment_time <= #{dto.endDate} )t1 group by order_id ) t2 left join ( select ois.order_id, IFNULL(sum(ois.fee_supplier),0) as fee_supplier, IFNULL(sum(ois.fee_partner),0) as fee_partner, IFNULL(sum(ois.fee_platform),0) as fee_platform, IFNULL(sum(ois.fee_platform_pack),0) as fee_platform_pack, IFNULL(sum(ois.fee_platform_check),0) as fee_platform_check, IFNULL(sum(ois.fee_platform_transport),0) as fee_platform_transport, IFNULL(sum(ois.total_fee),0) as total_fee, IFNULL(sum(ois.fee_packing_transport),0) as fee_packing_transport from t_order_item_sales ois group by order_id )t3 on t2.order_id =t3.order_id