select distinct
a.contcode,
decode(d.period,1,d.factor)"1YR",
decode(d.period,2,d.factor)"2YR",
decode(d.period,3,d.factor)"3YR",
decode(d.period,4,d.factor)"4YR",
decode(d.period,5,d.factor)"5YR"
from contlink a
join plans b on a.plangrp = b.plangrp
join earnings_account_classes c on a.contcode = c.account_class_code
join earnings_factors d on c.account_class_id = d.account_class_id
where b.program in ('AT','EIPP','RUP','WP','CW','MCK','PDR','TW','WR','WRR')
and b.term in (12,24,36,48,60,72,84,96,108,120)
and a.end_date is null
order by 1;
目前的数据如下:
CONTCODE | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A01 | A03 | A03 | A05 | A05 | A05 | A07 | A07 | A07 | A07 | A09 | A09 | A09 | A09 | A09 |
也许是这样的:
select distinct
a.contcode,
sum(decode(d.period,1,d.factor))"1YR",
sum(decode(d.period,2,d.factor))"2YR",
sum(decode(d.period,3,d.factor))"3YR",
sum(decode(d.period,4,d.factor))"4YR",
sum(decode(d.period,5,d.factor))"5YR"
...
group by a.contcode
order by 1;
Bobby