select cu.customer_id as ID,cu.customer_name as NAMA,cu.customer_phone as PHONE1,cu.customer_phone_2 as PHONE2,cu.customer_address as ALAMAT, pl.product_id as PRODUK,cs.calling_strike_name,(select max(calling.phone_date)
from calling where calling.customer_id=cu.customer_id and calling.calling_target_name=pl.consumed_by) as telepon  from customer cu
inner join product_log pl on pl.customer_id=cu.customer_id
inner join calling ca on ca.customer_id=cu.customer_id
inner join calling_strike cs on cs.calling_strike_id=ca.calling_strike_id
where ca.calling_strike_id='10'
and pl.product_id='lacta'
and cu.submit_date<='2010-12-09'
and pl.consumed_by=cu.customer_id
and
(select ca2.calling_strike_id from calling ca2
where ca2.customer_id = cu.customer_id
and ca2.phone_date =
(select max(ca1.phone_date) from calling ca1 where ca1.customer_id = cu.customer_id) limit 1)
not in ('12', '17')
group by cu.customer_id
order by cu.customer_name

0 Comments:

Post a Comment