count(DISTINCT t.order_id) orders,max(t.clearing_amount)max_order,ifnull(sum(if(t.refund_id is not null,if(t.transaction_type='Debit',t.clearing_amount,-t.clearing_amount),0)),0)refund_amount,
ifnull(sum(if(t.refund_id is not null, if(t.transaction_type='Debit', t.clearing_amount, -t.clearing_amount), 0)), 0) refund_amount,
ifnull(sum(if(t.refund_id is not null and t.transaction_type='Debit', 1, 0)), 0)refund_orders, max(if(t.refund_id is not null and t.transaction_type='Debit', t.clearing_amount, 0)) max_refund
ifnull(sum(if(t.refund_id is not null and t.transaction_type='Debit', 1, 0)), 0)refund_orders, max(if(t.refund_id is not null and t.transaction_type='Debit', t.clearing_amount, 0)) max_refund
FROM sys_clients p
FROM sys_clients p
INNER JOIN pmt_transactions t ON t.client_id = p.client_id and (t.transaction_type='Credit' or t.refund_id is not null)
INNER JOIN pmt_transactions t
INNER JOIN pmt_orders o ON t.order_id = o.order_id
ON t.client_id = p.client_id
WHERE o.create_time >= #{begin} AND o.create_time <= #{end}
and (t.transaction_type = 'Credit' or t.refund_id is not null)
INNER JOIN pmt_orders o
ON t.order_id = o.order_id
WHERE o.create_time >= #{begin}
AND o.create_time <= #{end}
]]>
]]>
<iftest="org_id!=null and org_ids==null">and p.org_id=#{org_id}</if>
ifnull(sum(if(t.refund_id is not null, if(t.transaction_type='Debit', t.clearing_amount, -t.clearing_amount), 0)), 0) refund_amount,
ifnull(sum(if(t.refund_id is not null and t.transaction_type='Debit', 1, 0)), 0)refund_orders, max(if(t.refund_id is not null and t.transaction_type='Debit', t.clearing_amount, 0)) max_refund