Hi Nagornyi,
Thanks a lot for all your help, I am still having the problem and I found that part of the problem is with the data also. But now I have a clean set of data which I am running only for a certain year range and it getting me three distinct different values and I want them to sum into one and display.
I am also sending you my sql
select distinct BC_NAME, BC_TYPE,
case when a.ACCT_NO_4 in ('06','16') then 'Meter Cost'
when a.ACCT_NO_4 in ('04','17') then 'Meter Install Cost'
when a.ACCT_NO_4 in ('02','11') then 'Service Cost'
when a.ACCT_NO_4 in ('07','12') then 'Regulator Cost' else '' end as ct_type,
f.start_year,
case when a.ACCT_NO_4 in ('06','16') then sum(AFTER_COND_FCT_AMT) OVER (PARTITION BY a.wr_no,a.ACCT_NO_4)
when a.ACCT_NO_4 in ('04','17') then sum(AFTER_COND_FCT_AMT) OVER (PARTITION BY a.wr_no,a.ACCT_NO_4)
when a.ACCT_NO_4 in ('02','11') then sum(AFTER_COND_FCT_AMT) OVER (PARTITION BY a.wr_no,a.ACCT_NO_4)
when a.ACCT_NO_4 in ('07','12') then sum(AFTER_COND_FCT_AMT) OVER (PARTITION BY a.wr_no,a.ACCT_NO_4) end sum_amt,
from wac a,
wce b,
wr c,
bcaa d,
bwr e,
wdr g,
bbc h,
bbcl i
where h.bciid = i.bcid and
d.id = e.bcaa_id and
a.wr_no = b.wr_no and
a.wr_no = e.wr_no and
a.wr_no = c.wr_no and
a.wr_no = g.wr_no and
g.status_code = 'O' and
a.D_AB_DA = b.D_AB_DA and
b.D_AB_DA = 'D' and
e.bcaa_id = 323 and
a.ACCT_NO_4 in ('06','16','04','17','02','11','07','12') and
b.cost_type_code in ('MAT','LAB') and
c.fiscal_year = '2005' and
c.fiscal_year in (select fiscal_year + rownum - 1 column_year from all_tables where rownum <= d.NUMBER_OF_YEARS)
group by c.fiscal_year, b.ID_COST_TYPE_CODE,a.ACCT_NO_4,BC_NAME, BC_TYPE
This is result I am getting.
BC_NAME,BC_TYPE,COST_TYPE,FISCAL_YEAR,SUM_AMT
NV HOMES,LSF,Meter Cost,2005,144
NV HOMES,LSF,Meter Install Cost,2005,98.049
NV HOMES,LSF,Service Cost,2005,1245.441
NV HOMES,LSF,Service Cost,2005,1987.761
NV HOMES,LSF,Service Cost,2005,3286.821
PULTE,SF,Meter Cost,2005,144
PULTE,SF,Meter Install Cost,2005,98.049
PULTE,SF,Service Cost,2005,1245.441
PULTE,SF,Service Cost,2005,1987.761
PULTE,SF,Service Cost,2005,3286.821
RYAN,TH,Meter Cost,2005,144
RYAN,TH,Meter Install Cost,2005,98.049
RYAN,TH,Service Cost,2005,1245.441
RYAN,TH,Service Cost,2005,1987.761
RYAN,TH,Service Cost,2005,3286.821
For service cost I am getting three records, is there any way in the sql I can combine this three into one record and show. Any help will be very mcuh appreciated on this.
Thanks a lot.