select aa.customer_id, aa.customer_name, aa.customer_address, aa.customer_phone, aa.pointtype, (aa.satu + aa.dua) as point
from
(
select pr.customer_id, cu.customer_name, cu.customer_address, cu.customer_phone, 
         (case when pr.point_reward_type_id  = "1" then "Point Reward"
                  when pr.point_reward_type_id = "2" then "Redeemed" end) as pointtype,
         (case when pr.point_reward_type_id = "1" then sum(pr.total_point) else 0 end) as satu,
         (case when pr.point_reward_type_id = "2" then sum(pr.total_point) else 0 end) as dua
from point_reward as pr, customer cu
/* where pr.customer_id = "081001080800040022" */
where  pr.customer_id = '01080800040427' and pr.customer_id = cu.customer_id
group by pr.customer_id, pr.point_reward_type_id
order by pr.customer_id, pr.point_reward_type_id
) aa
order by aa.customer_id, aa.customer_name, aa.customer_address, aa.customer_phone, aa.pointtype

0 Comments:

Post a Comment