select A.sa_ctcode,A.ct_ltd, sum(A.sa_2003), sum(A.sa_2004),
sum(A.sa_2005) from
(select sa_ctcode, ct_ltd, sum(sa_chamt) as sa_2003, 0 as
sa_2004, 0 as sa_2005
from salelib.saletrs left outer join sujulib.custmst on
sa_ctcode = ct_code
where sa_hisa='11' and sa_date between '20030101' and '20030131'
group by sa_ctcode,ct_ltd
union
select sa_ctcode, ct_ltd, 0 as sa_2003, sum(sa_chamt) as
sa_2004, 0 as sa_2005
from salelib.saletrs left outer join sujulib.custmst on
sa_ctcode = ct_code
where sa_hisa='11' and sa_date between '20040101' and '20040131'
group by sa_ctcode,ct_ltd
union
select sa_ctcode, ct_ltd, 0 as sa_2003, 0 as sa_2004,
sum(sa_chamt) as sa_2005
from salelib.saletrs left outer join sujulib.custmst on
sa_ctcode = ct_code
where sa_hisa='11' and sa_date between '20050101' and '20050131'
group by sa_ctcode,ct_ltd
) A
group by A.sa_ctcode, A.ct_ltd
*구문상 머가 잘못되었는가요? 서브쿼리 입니다.
|