1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Help suming query fields.

Discussion in 'SQL PL/SQL' started by gammaman, May 2, 2010.

  1. gammaman

    gammaman Guest

    i have this query that produces the first three columns below. I would like to add a fourth column (Not in the database just in a display).
    This fourth column will store a running total of the order Qty of each ordered item for a specific contract.

    Code (Text):

    Contract#      Item#     Order Qty    Running Total
    1001              1008           10                  10
    1001              1008           12                  22
    1002              1008            2                    2
    1002              1008            3                    5
     

    See the running total column I created, that is what I want to produce. Here is the code that creates the query for the first three columns

    Code (Text):

     $summary = oci_parse($conn,'select "CONTRACTS"."CONTRACTNO" as "CONTRACTNO",
         "MADEOF"."ITEMNUM" as "ITEMNUM",
         "MADEOF"."ORDERQTY" as "ORDERQTY"
     from    "ORDERS" "ORDERS",
         "MADEOF" "MADEOF",
         "CONTRACTS" "CONTRACTS"
     where   "ORDERS"."CONTRACTNUM"="CONTRACTS"."CONTRACTNO"
     and     "MADEOF"."ORDERNUM"="ORDERS"."ORDERNO"');
     
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,346
    Likes Received:
    347
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You need to use the analytic form of SUM() to generate such a report. An example in the Oracle online documentation is found here:

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions163.htm#SQLRF06115

    at the bottom of the page.