* Hello everbody I'm doing a self study on writing queries in SQL. Now I wrote this query below but i does not give me the correct result.
When I countup (B + C + D + E) The outcome has to be equal to A. but that is not the case it is higher
Can you tell me what I'm doing wrong in these query???? I'm new in this and I'm doing a self study
and I'm doing try and error for already two weeks on this, and i don't understand what i'm doing wrong and why.
I,m working with oracle 10G
Thanks for your suport
Regards
Alfonso F Jansen*/

select
A.month, sum(A.Total_Value), sum(B.Value1),
sum(C.Value2), Sum(D.Value3), sum(E.Value4)
From
(select To_Char(t2.asmt_date, 'MON-yyyy')month,
sum(t1.sadt1_stat_val)Value4
From sad_t1 t1, sad_t2 t2
where t1.key_year = t2.key_year
and t1.key_nber = t2.key_nber
and t1.proc = '3071'
and t2.sad_asmt_date between '01-jan-2010' and '30-apr-2010'
group by t2.sad_asmt_date
)E,
(select To_Char(t2.asmt_date, 'MON-yyyy')month,
sum(t1.sadt1_stat_val)Value3
From sad_t1 t1, sad_t2 t2
where t1.key_year = t2.key_year
and t1.key_nber = t2.key_nber
and t1.proc = '3072'
and t2.sad_asmt_date between '01-jan-2010' and '30-apr-2010'
group by t2.sad_asmt_date
)D,
/* looking for the totaal price of this products*/
(select To_Char(t2.asmt_date, 'MON-yyyy')month,
sum(t1.sadt1_stat_val)Value2
From sad_t1 t1, sad_t2 t2
where t1.key_year = t2.key_year
and t1.key_nber = t2.key_nber
and t1.proc in('1500','3151', '3152', '3171', '3172')
and t2.sad_asmt_date between '01-jan-2010' and '30-apr-2010'
group by t2.sad_asmt_date
)C,
/* looking for the totaal price of this products*/
(select To_Char(t2.asmt_date, 'MON-yyyy')month,
sum(t1.sadt1_stat_val)Value1
From sad_t1 t1, sad_t2 t2
where t1.key_year = t2.key_year
and t1.key_nber = t2.key_nber
and t1.proc in('1000','1200', '1400')
and t2.sad_asmt_date between '01-jan-2010' and '30-apr-2010'
group by t2.sad_asmt_date
)B,
/* looking for the total value*/
(select To_Char(t2.asmt_date, 'MON-yyyy')month,
sum(t1.sadt1_stat_val)Total_Value
From sad_t1 t1, sad_t2 t2
where t1.key_year = t2.key_year
and t1.key_nber = t2.key_nber
and t1.proc in('1000','1200', '1400', '1500', '3072', '3071' , '3151', '3152', '3171', '3172')
and t2.sad_asmt_date between '01-jan-2010' and '30-apr-2010'
group by t2.sad_asmt_date
)A
Where A.month = B.month
and A.month = C.month
and A.month = D.month
and A.month = E.month