Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> SQL Question
Hello all.
I have an intersting SQL question.
Suppose I have two tables with datasets, the # below mark the primary key. The first tableis the parent, and the second table is the child.
CONTRACTS
# CONTRACT_ID
# AMMENDMENT_ID
PARTICIPANTS CONTRACT_ID AMMEND_ID PARTICIPANTS ---------- ---------- ---------- 1 1 50 1 2 50 2 1 50 COMMITMENTS
# COMMITMENT_ID
CONTRACT_ID AMMENDMENT_ID VALUE COMMIT_ID CONTRACT_ID AMMEND_ID VALUE ---------- ---------- ---------- ---------- 1 1 1 500.56 2 1 1 25.25 3 1 2 75.45 4 1 2 30
If I issue the following query:
SELECT
CONTRACTS.CONTRACT_ID,
SUM(CONTRACTS.PARTICIPANTS) TOTAL_PARTICIPANTS,
SUM(COMMITMENTS.VALUE) TOTAL_DOLLAR_VALUE
FROM CONTRACTS, COMMITMENTS
WHERE COMMITMENTS.CONTRACT_ID(+) = CONTRACTS.CONTRACT_ID
AND COMMITMENTS.AMMEND_ID(+) = CONTRACTS.AMMEND_ID
GROUP BY CONTRACTS.CONTRACT_ID
I get these results:
CONTRACT_ID TOTAL_PARTICIPANTS TOTAL_DOLLAR_VALUE
---------- ---------- ---------- 1 200 631.26 2 50
What I was expecting was:
CONTRACT_ID TOTAL_PARTICIPANTS TOTAL_DOLLAR_VALUE
---------- ---------- ---------- 1 100 631.26 2 50
I can get around this by creating two views of the tables and then doing a select from these views. It works fine, however, why does the query alone not work??? Notice that the TOTAL_DOLLAR_VALUE is correct, but not the TOTAL_PARTICIPANTS value.
Any explanation/alternate solution would be nice.
Thanks in advance!
Brad
-- ---------------------------------------------------------------------------- --- Brad Worsfold Oracle DBA / Programmer bworsfold_at_vic.lgs.caReceived on Thu Jan 15 1998 - 00:00:00 CST
![]() |
![]() |