SELECT c.title as 'title' ,c.performanceId as 'performanceId', SUM(commiss) as 'commiss',c.timeEnd as 'timeEnd' FROM(
select o.performance_title as 'title',r.performance_id as 'performanceId' ,SUM(r.agent_distributions * (o.price_actual-o.price_refund)) as 'commiss',kp.time_end as 'timeEnd'
from (select * from kylin_order_tickets where created_at>DATE_SUB(CURDATE(), INTERVAL 6 MONTH)) as o
LEFT JOIN kylin_order_ticket_status as s on o.order_tickets_id=s.order_id
LEFT JOIN kylin_order_ticket_relations as r ON o.order_tickets_id=r.order_id
LEFT JOIN kylin_performances as kp ON r.performance_id= kp.performances_id
where r.agent_id=#{agentId} and s.pay_status='1' GROUP BY r.performance_id
UNION ALL
select o.performance_title as 'title',r.performance_id as 'performanceId' ,SUM(r.agent_distributions_master * (o.price_actual-o.price_refund)) as 'commiss',kp.time_end as 'timeEnd'
from (select * from kylin_order_tickets where created_at>DATE_SUB(CURDATE(), INTERVAL 6 MONTH)) as o
LEFT JOIN kylin_order_ticket_status as s on o.order_tickets_id=s.order_id
LEFT JOIN kylin_order_ticket_relations as r ON o.order_tickets_id=r.order_id
LEFT JOIN kylin_performances as kp ON r.performance_id= kp.performances_id
where r.agent_id_master=#{agentId} and s.pay_status='1' GROUP BY r.performance_id