A slightly different running sum in a hierarchy query

Hi,
I've got stuck with this problem since quite some time, so pls help:
I am basically trying to rollup/aggregate values from the lower level nodes to the upper level nodes in a hierarchy. But this aggregate is a bit different than a plain rollup of values.
create table ent_rel (parent number, child number, child_amount number);
insert into ent_rel
select null, 100, null from dual
union all select 100, 101, null from dual
union all select 101, 102, 20 from dual
union all select 102, 103, null from dual
union all select 103, 104, null from dual
union all select 104, 105, null from dual
union all select 105, 106, 40 from dual
union all select 106, 107, null from dual
union all select 107, 108, 20 from dual
union all select 107, 109, 10 from dual
union all select 101, 203, null from dual
union all select 203, 205, 50 from dual
union all select 205, 207, null from dual
union all select 207, 209, null from dual
union all select 209, 210, 10 from dual
commit;
select RPAD(' ', (LEVEL - 1) * 2, '-') || child child
,level
,child_amount
from ent_rel
start with parent is null
connect by prior child = parent
CHILD LEVEL CHILD_AMOUNT
100 1
--101 2
----102 3 20
------103 4
--------104 5
----------105 6
------------106 7 40
--------------107 8
----------------108 9 20
----------------109 9 10
----203 3
------205 4 50
--------207 5
----------209 6
------------210 7 10
Now, I need a SQL query or even a simple PL/SQL code to get the DESIRED_AMOUNT field as shown below:
Pls note that there might be many more parallel branches to a node, but I've kept it simple just to get the concept.
CHILD LEVEL CHILD_AMOUNT DESIRED_AMOUNT
100 1 70
--101 2 70
----102 3 20 20
------103 4 40
--------104 5 40
----------105 6 40
------------106 7 40 40
--------------107 8 30
----------------108 9 20 20
----------------109 9 10 10
----203 3 50
------205 4 50 50
--------207 5 10
----------209 6 10
------------210 7 10 10
Thanks a lot in advance.
thanks and regards,
Knl

Hi,
Welcome to the forum!
Thanks for posting the CREATE TABLE and INSERT statements! That's very helpful.
It's also helpful if you format your code and output. When posting formatted text on this site, type these 6 characters:
\(all small letters, inside curly brackets) to keep the site from compressing the spaces.
You can do two CONNECT BY queries: one to get the desired amount, and the other like you're already doing, to get the indented child column.  The first will differ in that it has no START WITH clause, which means every node in your table will be the root of a tree, and that there's an additional CONNECT BY condition to quit looking for descendants as soon as an amount is found.  This corresponds to your apparant requirement that the desired_amount is the amount, if it is not NULL, and only otherwise is the sum of the desired_amounts of one's descendants.WITH     desired_amount_tree     AS
     SELECT     CONNECT_BY_ROOT child     AS root
     ,     child
     ,     child_amount
     FROM     ent_rel
     CONNECT BY     PRIOR child          = parent
          AND     PRIOR child_amount     IS NULL
,     got_desired_amount     AS
     SELECT     root
     ,     SUM (child_amount)     AS desired_amount
     FROM     desired_amount_tree
     GROUP BY root
select      RPAD ( ' '
     , (LEVEL - 1) * 2
     ) || e.child      AS child
,     level
,     e.child_amount
,     desired_amount
from      ent_rel               e
JOIN     got_desired_amount     d     ON     e.child     = d.root
start with      parent           is null
connect by      prior child      = parent
It's usually more efficient to do join after doing the CONNECT BY.  For better performance, try doing your original query by itself, and then joining its result set to got_desired_amount.
Of course, it would be a lot more efficient if we could eliminate the extra CONNECT BY query.  That might be possible using MODEL or (starting in Oracle 11.2) a recursive sub-query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Published site slight different

    When publishing my site to a folder on my computer it looks slightly different to how it does in iWeb. Some text is underlined and the alignment is not quite how it should be.
    This isn't a problem with hosting the site on the net, it's something to do with what happens to the site in iWeb as it's being published to the folder.
    Any ideas?

    On the Contact page, try increasing the size of the text box slightly. It loads with a return after "Email:" before it straightens itself out. Also do a Command A on pages to check that objects/text boxes are not touching or overlapping.
    If you tried the troubleshooting steps and they didn't fix the underlined text problem you need to go one step further.
    Delete the offending text, save and quit iWeb
    Delete the .plist, reboot your Mac and run Disk Utility to repair permissions
    Launch iWeb, add the text, save and publish
    Deleting the text and rebooting gets rid of the screwed up info from the domain file. Doing a restart is the only way to clear redundant files out of iWeb so you should do it regularly.

  • "Display As Running Sum" Feature

    Hi
    Tried to use "Display As Running Sum" feature and it looks like it adds all the values across the pivot table and does not reset it on a new row...
    So for instance we ahve a table as follows
    A 1 2
    A1 3 4
    A2 5 6
    After running sum applied:
    A 1 3
    A1 6 10
    A2 15 21
    Is there any way value could be reset after each row ? Any hidden configuration file to be changed ?

    Initial data is:
    Product Date Value
    A Day1 1
    A Day2 2
    A Day3 3
    A1 Day1 4
    A1 Day2 5
    A1 Day3 6
    A2 Day1 7
    A2 Day2 8
    A2 Day3 9
    Pivot table looks like:
    ---- Day001 Day002 Day003
    A 1 2 3
    A1 4 5 6
    A2 7 8 9
    Required table (values disaplyed as running sums by product)
    ---- Day001 Day002 Day003
    A 1 3 6
    A1 4 9 15
    A2 7 15 24
    PROBLEM: its easy to create formula RSUM(value by product) and put it as pivot table measure BUT I have around 1000 reports with different dimensions which requires to create RSUM(value by dimension1), RSUM(value by dimension2) ... RSUM(value by dimension1000) and its sort of nightmare...
    Instead of RSUM I thought that feature "Display As Running Sum" could be used, but its not working as expected in terms of it does not get reset for each row. How do I configure "Display As Running Sum" to reset value for each row ?
    PS: this is what "Display As Running Sum" gives
    ---- Day001 Day002 Day003
    A 1 3 6
    A1 10 15 21
    A2 28 36 45

  • Running Sum on Sorted data & freeze panes?

    Hi all,
    Brand new to Web Intelligence XI, so learning whilst putting together first report, however need some guidance and help on the following. 
    I have a basic report which is sorted by highest ytd sales within the report and has breaks at each change in brand category.
    I need to be able to provide a running % cumulative total for each article within each brand category based on the highest ytd  sales.
    I have tried using the running sum formula but this does not give correct results due to the sort, as when this is taken off
    the formula is correct.  Have different varients of this after reviewing the forum but unfortunately still cannot get this basic calculation to work.
    My second question is that when viewing a lot of data, is it yet possible to freeze the headers in each column?
    Thanks in advance for any help given.
    Nick

    Freeze panes will be supported in BO 4.1 which is planned to be released in Q3 2013.
    Check the details below:
    http://scn.sap.com/community/businessobjects-web-intelligence/blog/2013/03/10/what-is-new-with-web-intelligence-bi-41-part-2-core-capabilities
    http://scn.sap.com/community/business-intelligence/blog/2013/01/31/sap-businessobjects-bi-41-update-and-bi4x-roadmap-asug-webcast-part-1
    http://scn.sap.com/community/business-intelligence/blog/2013/02/01/sap-businessobjects-bi-41-update-and-bi4x-roadmap-asug-webcast-part-2

  • Powerpoint renders slides slightly differently on different Macs

    I have again this weird problem with Powerpoint.
    Sometimes, slides look differently on different machines.
    The difference is not very large, but definitely noticeable, in particular, if there are other objects on the slide besides the text.
    For an example please see
    1. (MacBookPro)
    PDF: http://zach.in.tu-clausthal.de/tmp/pptonmacbook.pdf
    PNG: http://zach.in.tu-clausthal.de/tmp/pptonmacbook.png
    2. (Modbook)
    PDF: http://zach.in.tu-clausthal.de/tmp/pptonmodbook.pdf
    PNG: http://zach.in.tu-clausthal.de/tmp/pptonmodbook.png
    The effect is most pronounced on the first line of bullet 2. (The "R^d" thing is an image.)
    I created the PDFs using the print command in Powerpoint and then saving to PDF.
    I created the PNG taking a screenshot.
    As you can see, there are two problems:
    1.
    When I print the slide on the MacBook to PDF, the layout of the text is slightly different than on screen.
    2.
    The layout of the text looks different on both machines.
    Both machines run Mac OS 10.6.2 (Snow Leopard).
    The powerpoint versions on both machines are identical and up-to-date (12.2.3).
    The powerpoint files on both machines are identical (just copied).
    I use an in-house font on the slides, which is StoneSansITC; I copied the font files from one machine to the other; they all reside in ~/Library/Fonts, and this is the only place where these font files are located.
    I have checked with 'pdffonts' and it seems to me that the Stone fonts are indeed correctly embedded in the PDFs. Here is the output of pdffonts:
    % pdffonts pptonmodbook.pdf
    name type emb sub uni object ID
    NNCXIS+Symbol TrueType yes yes yes 24 0
    TYRNZE+Helvetica TrueType yes yes yes 21 0
    RTAEGG+MSBM10 Type 1 yes yes no 26 0
    ZXGVHI+StoneSansITCStd-Medium Type 1C yes yes no 8 0
    ZXGVHI+StoneSansITCStd-Medium Type 1C yes yes yes 17 0
    RTAEGG+CMSSI8 Type 1 yes yes no 27 0
    ZJTMTS+StoneSansITCStd-MediumItalic Type 1C yes yes no 22 0
    JHAIES+Wingdings TrueType yes yes yes 19 0
    With pptonmacbook.pdf, pdffonts yields very similar output.
    In Powerpoint, I have checked File -> Properties -> Contents, and the list under "Fonts Used" shows the StoneSansITC fonts alright.
    The compatibility report in Powerpoint does not report any issues with fonts (only a few warnings about animations, movies, and "some shapes cannot be changed in earlier versions ..").
    Does anyone have an idea how I could resolve this differences in rendering?
    All hints, suggestions, and insights will be highly appreciated.
    Best regards,
    Gabriel.

    Perfect candidate for this forum: http://www.officeformac.com/ProductForums/PowerPoint/

  • TS3243 My time machine back up freezes at a partial backup. I keep cancelling and restarting a new back up and it will again freeze up at a slightly different point. Last freeze shows 485bytes of 246.16 GB. My last backup was Sept. 1 !!!!! Help!!!!

    Repeat: My time machine back up freezes at a partial backup. I keep cancelling and restarting a new back up and it will again freeze up at a slightly different point. Last freeze shows 485bytes of 246.16 GB. My last backup was Sept. 1 !!!!! Help!!!!
    Also: am running OSX 10.6.8 on an iMac8,1
    TimeMachine had be working well on a 1TB WD MyBook Ext. H.D. .
    QUESTION: ANY SUGGESTIONS OR SOLUTIONS?????

    See Pondini's TM FAQs for starters.

  • Logical Columns - Running Sum & 3Month Rollover

    Hi All,
    Need to build a logical column.
    I have a column with number of units (count distinct) in RPD.
    I need to build a new logical column in the REPOSITORY , such that it has running sum values.... sothat when i pick this #units column and months column in the ANSWERS...I need to get roll over of all previous values for first month.
    Say Jan ---> XXXX units ( summation of all previous available units - few years)
    Feb----> YYYY units ( sum of till jan values & Feb units)
    Mar----> ZZZZ ...etc ( sum of till Feb values & Mar units) so on.
    Based on this newly built column I need to build another column of " 3 months roll over " column.
    Replies appreciated.
    Thanks in advance.

    Hi user11939829m
    So help me understand your new measures a little better. For the sake of this post, let's say your data is like so
    Month Year -- Units
    Jan 2010 -- 1
    Feb 2010 -- 2
    Mar 2010 -- 3
    Apr 2010 -- 4
    May 2010 -- 5
    Jun 2010 -- 6Then let's say you have a report with the above columns and the new running sum columns.
    Month Year -- Units -- Running Sum Units
    Jan 2010 -- 1 -- 1
    Feb 2010 -- 2 -- 3
    Mar 2010 -- 3 -- 6
    Apr 2010 -- 4 -- 10
    May 2010 -- 5 -- 15
    Jun 2010 -- 6 -- 21Now what exactly would your three months rollover be? Would the 3 month rolling sum = running sum for current month + running sum for last month + running sum for last last month?
    i.e.
    Month Year -- Units -- Running Sum Units -- 3 Month Rolling Sum
    Jan 2010 -- 1 -- 1 -- 1
    Feb 2010 -- 2 -- 3 -- 4
    Mar 2010 -- 3 -- 6 -- 10
    Apr 2010 -- 4 -- 10 -- 19
    May 2010 -- 5 -- 15 -- 31
    Jun 2010 -- 6 -- 21 -- 46Not sure what value such a measure would add. Or do you mean 3 month rolling sum would be the running sum for just the last three months (like below)? This makes more sense but in your description, you indicated that you'd build the 3 month rolling sum off of the running sum which confused me a bit.
    Month Year -- Units -- Running Sum Units -- 3 Month Rolling Sum
    Jan 2010 -- 1 -- 1 -- 1
    Feb 2010 -- 2 -- 3 -- 3
    Mar 2010 -- 3 -- 6 -- 6
    Apr 2010 -- 4 -- 10 -- 9
    May 2010 -- 5 -- 15 -- 12
    Jun 2010 -- 6 -- 21 -- 15 Is that what you are going for? Please elaborate.
    Best regards,
    -Joe

  • In  iTunes: why different run times for same track?

    I have occasional repeats of the same given track stored in iTunes. Sometimes, the 2 identical tracks show different running times. This happens when one track came from the Net (downloaded before I started using iTunes, then imported into iTunes) and the other comes from a commercial CD. Do you know why the differing times? FYI: In each case, I have checked the endings of both tracks; they are identical, so the music is the same even though one track is rated to run [much] longer than the other. Also, in "Get Info" there's a way to change the running time of a track, but this is no solution: if I enter a shorter run time, the track will truncate itself, and finish playing before the proper end of the song -- if I enter a longer time, I get dead air after the end of the recording. Any ideas?
      Windows XP  
      Windows XP Pro  
      Windows XP Pro  

    "will iphone users in Singapore have access to application from other countries? "
    No. You can buy from the itunes store in the country in which you reside.
    Each country has the same rules:
    "SINGAPORE ONLY. The Service is available to you only in Singapore and is not available in any other location. You agree not to use or attempt to use the Service from outside of the available territory. iTunes may use technologies to verify such compliance."
    http://www.apple.com/legal/itunes/appstore/sg/terms.html#APPS

  • Since this morning all text in firefox look slightly different - I think it still uses the same font, but renders it differently.

    Since this morning all text in firefox looks slightly different - I think it still uses the same font, but renders it differently!? I would like to have it changed back to what it was. Any help is welcome.
    Some facts:
    - Happens only in Firefox (IE & Chrome still look the same)
    - Already did a reset to defaults
    I'm using the latest version of Firefox
    Screenshot can be found here: [http://www.ka-pow.net/media/images/firefoxissue.jpg link text]

    Reset the page zoom on pages that cause problems: <b>View/Beeld > Zoom > Reset</b> (Ctrl+0 (zero); Cmd+0 on Mac)
    *http://kb.mozillazine.org/Zoom_text_of_web_pages
    Press F10 or tap the Alt key to bring up the "Menu Bar" temporarily if the Menu Bar is hidden.
    Use "Firefox > Options" instead of "Tools/Extra > Options" if the menu bar is hidden.

  • Running Sum in Pivot Table

    Hi Experts,
    I have the following pivot table:
    ----------SUM1--SUM2--SUM3
    -------A--20------30-------45
    -------P--10------15--------5
    ----DIFF-10------15-------40
    where the last row is new calculated item. Is it possible to create another calculated row by using value from the 'Diff' row?. What I want to achieve is Running Sum for 'Diff' row.
    So I need an output like:
    ----------SUM1--SUM2--SUM3
    -------A--20------30-------45
    -------P--10------15--------5
    ----DIFF-10------15-------40
    RSUM-10----25-------65
    My BI version is BI EE 10.1.3.4.1. I suppose that some kind of trick will be helped.
    Thanks in advance for any suggestion
    Regards,
    Esk

    Hi, It is possible in pivot view.
    You need to move the measure labels to the left..where it says rows.
    Once that is done, we can click on any of the facts and choose display as running sum

  • Running sum per column in pivot table

    Hello,
    I am facing a problem with a running sum in a pivot table. As you know, the running sum provided by OBIEE spans across rows and columns. My requirements force me to have a running sum per each column (I have four columns, one for each quarter of the year). My pivot is as follows:
    ------------------------------|| 1st Quarter / 2nd Quarter ...
    type of product / status || (Measure / Running Sum) / (Measure / Running Sum) ...
    I've tried using the evaluate function with a "sum over" but that doesn't seem to work either.
    Do you have any ideas that could be useful to solve this?
    Thank you in advance for your time,
    João Marques

    Do not use the "running measure" button in pivot table, but try this :
    edit the formula of your measure and type :
    RSUM(mesure by dimension)
    where dimension is the attribute dimension that you put on the ROWS of your pivot table
    Exemple : I've got the criteria REVENUE, YEAR, CUSTOMER TYPE
    I put the YEAR in the Columns of the pivot table
    I put the CUSTOMER TYPE on the rows of the pivot table
    I put the REVENUE in the measures of the pivot table
    Measure has the formula : RSUM("Facts Revenue".Revenue BY Customers."Customer Type")

  • Question - Y do my fonts look slightly different when publish site to .mac?

    I've created a website on iWeb but when i publish it and view it in safari the fonts look slightly different. It's hard to explain but they basically just look worse. Can anyone let me know why this might be and how i could fix this problem. Thanks in advance.

    Quit iWeb, go to Home Folder/Library/Preferences and delete the file com.apple.iWeb.plist.
    Restart your Mac, launch iWeb and republish.
    You should really convert any text done in "copperplate" to an image. Otherwise it will be converted to an (ugly) alternative on any computer that doesn't have this font installed.

  • Display as Running Sum

    I have a measure in the pivot table with the following options enabled:
    - Show data as - Percent of - Section
    - Display as Running Sum
    Also, I have several sections in the pivot table.
    The measure result is correct, but when I add totals, I get a strange result. The total for the first section is 100%, for the second section is 200%, for the third section is 300%, and so on.
    Does everybody get this problem? How can I solve it?
    Thanks.

    I couldn't find a solution... I gave up using "Display as Running Sum" and I created in the criteria tab a formula to solve this (using RSUM BY).

  • NM output is slight different than in MA

    Hi guys,
    one questions from MA newbe.
    i use default parser in NM and default viewpoint in MA,
    but there are some missing information in MA:
    No router preference and output is slight different than in NM, like A is H now.
    i used before NM, but now trying to swith over MA
    Thanks for help

    Yes, I believe this is a bug.  I've filed one and hopefully we can get this addressed in the next public release.
    Paul

  • Running Sum without analytic function

    Hi
    I have data like below
    Create table Test (Name Varchar(30),M Int, Y Int, Val Int);
    Insert into Test Values ('A',1,2011,2);
    Insert into Test Values ('A',2,2011,2);
    Insert into Test Values ('A',3,2011,2);
    Insert into Test Values ('A',4,2011,2);
    Insert into Test Values ('A',5,2011,2);
    Insert into Test Values ('A',6,2011,2);
    Insert into Test Values ('A',7,2011,2);
    Insert into Test Values ('A',8,2011,2);
    Insert into Test Values ('A',9,2011,2);
    Insert into Test Values ('A',10,2011,2);
    Insert into Test Values ('A',11,2011,2);
    Insert into Test Values ('A',12,2011,2);
    Insert into Test Values ('A',1,2012,2);
    Insert into Test Values ('A',2,2012,2);
    Insert into Test Values ('A',3,2012,2);
    Insert into Test Values ('A',4,2012,2);
    Insert into Test Values ('A',5,2012,2);
    Insert into Test Values ('A',6,2012,2);
    Insert into Test Values ('A',7,2012,2);
    Now based on above data I need to calculate running sum for past 18 Months. Condition is I can not use analytic function or Oracle specific SQL functions (for portability).
    I tries following SQL but it dint work
    select Name,rnk, SUM(val) from (
    SELECT a.Name,a.m,a.Y,b.val, count(*) rnk
    from Test a, Test b
    where (a.Name=b.Name and (a.M <= b.M and a.Y<= b.Y))
    group by a.Name,a.Y,a.m
    order by a.Name,a.Y,a.m
    ) abc
    group By Name,rnk
    Order by Name,rnk
    Can some one give suggastion.

    Hi,
    I don't see what your query or your desired results have to do with the last 18 months. Is the task here to show for a given month (July, 2012, for example) the total of the 18 months ending in that month (February, 2011 through July, 2012 in this case) for the same name? If so:
    SELECT       c.name, c.y, c.m
    ,       SUM (p.val)     AS running_total
    FROM       test     c
    JOIN       test     p  ON     ( ((12 * c.y) + c.m)
                   - ((12 * p.y) + p.m)
                   ) BETWEEN 0 AND 17
    GROUP BY  c.name, c.y, c.m
    ORDER BY  c.name, c.y, c.m
    ;Output:
    NAME                Y          M RUNNING_TOTAL
    A                2011          1             2
    A                2011          2             4
    A                2011          3             6
    A                2011          4             8
    A                2011          5            10
    A                2011          6            12
    A                2011          7            14
    A                2011          8            16
    A                2011          9            18
    A                2011         10            20
    A                2011         11            22
    A                2011         12            24
    A                2012          1            26
    A                2012          2            28
    A                2012          3            30
    A                2012          4            32
    A                2012          5            34
    A                2012          6            36
    A                2012          7            36

Maybe you are looking for

  • Problem on Intel Hd Graphic 4000

    Hi, guys! I just formated my notebook (HP Pavilion dv7-7047cl) and instaled the drivers from the HP Support center. Everything looks great, except for the INtel HD Graphic 4000, that shows a yellow exclamation on the drive list. My notebook also have

  • Crashes at startup, every time

    Last night Logic Pro 7 (7.2.1 on OS X 10.4.7) started crashing on startup. I hadn't installed anything new to the system, and in fact the last time I had exited Logic, it was a clean exit. Now it's been 24 hours and I still can't get anywhere with it

  • Take Image Of Computer And Load It Onto A Brand New MacBook Pro

    Hello, I just purchased a MacBook Pro 13". I currently have a MacBook original (White Shell with Snow Leopard) which I want to mirror completely over to the new MacBook Pro. So what I want is to completely erase (format) the new MacBook Pro and then

  • All the fire wire ports quit  working.

    Hello to all. As you see I am a newbie on here. Last night I was transferring files from my exteranl FW400 to my other FW800 which are daisy chained together. Ive done this hundreds of times. Last night as I made sure at least one of the files transf

  • Archiving problem for Windows OS...

    Hi all, I was trying to archive the messages. I followed the below document settings and created the archiving not able to archive the messages. https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/402fae48-0601-0010-3088-85c46a236f50