Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> select and insert-select statements have different results

select and insert-select statements have different results

From: Blaenzo <blaenzo_at_hotmail.com>
Date: 1 Jun 2006 04:55:34 -0700
Message-ID: <1149162933.989153.241240@j55g2000cwa.googlegroups.com>


Hi,
I'm completely stuck on the following:

I run a select query to fill an EMTPY table with (summed) data.

Then, however, the total sum of all records doesn't match the total sum of the direct query on the original table.

Both tables have the same layout.

How can the total sum of SUMMED/GOUPED BY data be different from the total sum of the original data with the EXACT same select statement??

I use Oracle 10g.
These are my queries:

//empty destination table

TRUNCATE TABLE AGGPNLVECTOR
//fill table with aggregated numbers

INSERT INTO AGGPNLVECTOR
SELECT 'AGG1680', MRTKCOBDATE, PNLVECTORTYPEID, SCENARIOID,     ELEMENTNUMBER ,SUM(NEWVALUE),ERRORSTATUS, RISKFACTORGROUPID,     NEWIGNOREREPORTSTATUS, SUM(ALTVALUE) FROM PNLVECTOR
WHERE MRTKCOBDATE='1-MAY-06'
AND SCENARIOID=0
AND ERRORSTATUS='V'
AND NEWIGNOREREPORTSTATUS='R'
AND (
    PNLVECTOR.DESKLONGID='DSK1116'
    OR PNLVECTOR.DESKLONGID='DSK1120'
    OR PNLVECTOR.DESKLONGID='DSK1644'
    )

GROUP BY MRTKCOBDATE, PNLVECTORTYPEID, SCENARIOID,     ELEMENTNUMBER ,ERRORSTATUS, RISKFACTORGROUPID,     NEWIGNOREREPORTSTATUS
//total sum no.1

SELECT SUM(NEWVALUE)
FROM PNLVECTOR
WHERE MRTKCOBDATE='1-MAY-06'
AND SCENARIOID=0
AND ERRORSTATUS='V'
AND NEWIGNOREREPORTSTATUS='R'
AND (
    PNLVECTOR.DESKLONGID='DSK1116'
    OR PNLVECTOR.DESKLONGID='DSK1120'
    OR PNLVECTOR.DESKLONGID='DSK1644'
    )

//total sum no. 2

SELECT SUM(NEW VALUE)
FROM AGGPNLVECTOR Many thanks!
Martijn Received on Thu Jun 01 2006 - 06:55:34 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US