I am trying to create a view/table, which is fecthing records from five different tables, and I need to calculate the sum of these fields in such a way that two tables have more than one value to add and I'm using SUM function to add their values. The SELECT statement looks something like that:
create table total_dues
as select
a.name,a.membership_no,(b.
due+sum(c.
due)+d.due
+e.regn_cg
_due+sum(f
.surcharge
_due))"Tot
al Dues"
from member a,land_cost b, dev_charges c,fee d, regn e,surcharge f
where a.membership_no=b.membersh
ip_no
and
a.membership_no=c.membersh
ip_no
and
a.membership_no=d.membersh
ip_no
and
a.membership_no=e.membersh
ip_no
and
a.membership_no=f.membersh
ip_no
group by a.name,a.membership_no,b.d
ue,d.due,e
.regn_cg_d
ue
/
The strange thing, which I have observed is that whenever SUM function is used more than once in the SELECT statement (as in the present case), the result is not correct i.e., the calculated sum of the fetched fields is always greater than the actual amount and when I skip one SUM function from the statement, the result is correct. This happens both in the case of creation of table and view. Why is that? Is something wrong with the syntax?
Another interesting thing is observed in the following simple SELECT statements used on the Oracle supplied sample tables:
select sum(sal),sum(dept.deptno)
from emp,dept
where emp.deptno=dept.deptno
In this particular case, the column sum(sal)gives the correct figure, while the column sum(dept.deptno) alwas gives the sum of deptno from emp table, even when I have used the dot notation to reference the dept table.
Should I rely on the Report Builder to design a report, because in this particular case we are calculating the sum of fields fetched from five different tables. The summary column in Report Builder only sums the fields from one individual table. Could you please guide me in the repect.
Thanks
Hassan Ayub
Start Free Trial