DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Tough Query - Cumulative value

  1. #1
    Join Date
    Mar 2002
    Location
    Mesa, Arizona
    Posts
    1,204

    Tough Query - Cumulative value

    How can I return a cumulative value in a raw dataset?


    raw data:
    ID VALUE
    -- -----
    1 5
    2 7
    3 2

    desired result:
    ID VALUE CUMULATIVE_VALUE
    -- ----- ----------------
    1 5 5
    2 7 12
    3 2 14
    "I do not fear computers. I fear the lack of them." Isaac Asimov
    Oracle Scirpts DBA's need

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    have a look in the sql reference for "Analytic Functions". They do exactly this, and look something like ...

    select id,value,
    sum(value) over (order by id range unbounded preceeding)
    from my_table
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width