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!

sum over partition and add in a initial query

BufossJan 20 2016 — edited Jan 20 2016

Hi all,

I have a complex query with the following structure

WITH

SUMMARY_TABLE AS

(

  SELECT /*+ MATERIALIZE*/

  --...............

  --..............

  -- .............

)

SELECT

   -- .........

FROM  TABLE20, TABLE30, TABLE40, TABLE50, SUMMARY_TABLE

WHERE  --.......

       --.......

AND SUMMARY_TABLE.COL1 = TABLE20.COL2

AND (:P_COUNT IS NULL OR SUMMARY_TABLE.COL2 IN

(select SUBSTR (  :P_STRING

                ,  INSTR (  :P_STRING,'<',1,ROWNUM) + 1

                ,  INSTR (  :P_STRING

                ,'>'

                ,1

                 ,ROWNUM)

             - (  INSTR (  :P_STRING

                ,'<'

                 ,1

                 ,ROWNUM) + 1))

                from dual

          CONNECT BY LEVEL <=::P_COUNT));

             

I also have the following connection of three more tables

SELECT TABLE1.COL1, TABLE2.COL2, TABLE3.COL3 ,  TABLE3.COL4

  FROM TABLE1, TABLE2, TABLE3

WHERE TABLE2.COL1 = TABLE1.COL1

   AND TABLE3.COL2 = TABLE2.COL2

With output :

COL1 COL2 COL3 COL4

1    3     5   100

1    3     10  300

4    1      2  100

2    2      3  100

2    2      1  200

=================

I want the query to be modified to sum the last column above and to be added to the initial query

COL1 COL2  COL4

1    3      400

4    1      100

2    2      300

Could you help me please ?

Thanks in advance

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2016
Added on Jan 20 2016
6 comments
408 views