select id as user_id,code ,SUM(dollar) as dollar ,country FROM (
select u.id,u.code,SUM(price) as dollar,u.country FROM pay_order p, user u where u.id = p.user_id AND p.status = 2 AND type = 0 AND p.created_time > NOW() - INTERVAL 30 DAY group by user_id UNION ALL
select u.id,u.code,SUM(dollar) as dollar,u.country FROM dealer_transfer_detail d, user u where u.id = d.receiver_id AND d.created_time > NOW() - INTERVAL 30 DAY group by receiver_id UNION ALL
select u.id,u.code,SUM(dollar) as dollar,u.country FROM dealer_transfer_detail_pink d, user u where u.id = d.receiver_id AND d.created_time > NOW() - INTERVAL 30 DAY group by receiver_id