Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Select with aggregated function strange behavior

846417Mar 21 2011 — edited Mar 21 2011
I created a simple query to reproduce this issue. The problem is when using SUM() between three tables, the values are not fetched as expected.


This is the simple script:

create table t1(clave number primary key,
descripcion varchar2(15));

create table t2(clave number primary key,
clave_t1 number,
total number,
CONSTRAINT t2_t1_fk
FOREIGN KEY (clave_t1)
REFERENCES t1(clave));

create table t3(clave number primary key,
clave_t1 number,
total number,
CONSTRAINT t3_t1_fk
FOREIGN KEY (clave_t1)
REFERENCES t1(clave));

insert into t1 values(1,'C7700');
insert into t2 values (1,1,1000000);
insert into t2 values (2,1,2000000);
insert into t2 values (3,1,5000000);
insert into t3 values (1,1,4000000);
insert into t3 values (2,1,5000000);
insert into t3 values (3,1,2000000);
insert into t3 values (4,1,3000000);

select sum(t2.total) t2total, sum(t3.total) t3total
from t1,t2,t3
where t2.clave_t1 = t1.clave
and t3.clave_t1 = t1.clave ;

Values fetched by the db engine are (32000000, 42000000) when they should be: (8000000,14000000). DB version is Oracle Express.

Thanks in advance for any help.
This post has been answered by 523861 on Mar 21 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2011
Added on Mar 21 2011
5 comments
127 views