How do data rollup for different levels?

I have a hierarchy of the company as below:
create table DI_COM (COM_ID varchar2(10), LEVEL_ID number, parent_com_id varchar2(10));
insert into DI_COM values ('1000000',1, null);
insert into DI_COM values ('1010000',2, '1000000');
insert into DI_COM values ('1010100',3, '1010000');
INSERT INTO DI_COM VALUES ('1010101',4, '1010100');

COM_ID   LEVEL_ID   parent_com_id
-----------------
1000000     1    null
1010000     2   1000000     
1010100     3   1010000     
1010101     4   1010100
And a fact table as below:
create table F_DATA (COM_ID varchar2(10), AMT number, QTY number);
insert into F_DATA values ('1010000',100,50);
insert into F_DATA values ('1010100',200,50);
insert into F_DATA values ('1010101',200,50);

COM_ID   AMT   QTY
------
1010000     100     50
1010100     200     50
1010101     200     50
I want rollup the data for each level in the hierarchy as below:
COM_ID   TAMT  TQTY
------
1000000   500 150
1010000   500 150
1010100   400 100
1010101   200 50    --corrected to 200
How can I do? Should which functions I use?


Thank you

Published by: PhoenixBai on January 14, 2011 11:03

DI_COM table is updated to reflect the hierarchical relationship between the listed companies.
Published by: PhoenixBai on January 14, 2011 14:13
SQL> select com_id
  2       , sum(amt) tamt
  3       , sum(qty) tqty
  4    from ( select connect_by_root c.com_id com_id
  5                , d.amt
  6                , d.qty
  7             from di_com c
  8                  left outer join f_data d on (c.com_id = d.com_id)
  9          connect by prior c.com_id = c.parent_com_id
 10         )
 11   group by com_id
 12   order by com_id
 13  /

COM_ID           TAMT       TQTY
---------- ---------- ----------
1000000           500        150
1010000           500        150
1010100           400        100
1010101           200         50

4 rows selected.

Kind regards
Rob.

Tags: Database

Similar Questions

  • How to set different date formats for different metadata fields?

    Hello

    Can I set different date for different fields of metadata formats? Standard Date format has a seconds. But I metadata fields, where I need to only show the date.

    I tried to use the rules and side effects. My code is: $xMyDate = formatDateOnly (xMyDate) $ >. But it does not work.

    Please how can I do?

    Thank you

    Martin

    Hi Laurent,.

    Large. This works. Good definition is:<$setValue("DOC_INFO","xDatumUkonceniRizeni",formatDateOnly(xDatumUkonceniRizeni))$>

    M.

  • How can I set up different levels of access on the SAA?

    I want to limit access for Branch staff prevent any change configuration on an ASA Firewall, routers and Catalyst switches.

    For switches and firewalls, I have configured the user with privilege 7 names and enabled local authentication (local connection).

    How can I do this on the ASA?

    Hello

    You can set up privilege levels on the SAA through the configuration of the AAA. Take a look at:

    http://www.Cisco.com/en/us/docs/security/ASA/asa72/asdm52/user/guide/devaccss.html

    HTH

    KeV

  • How to get results for different conditions of a line?

    Hello

    I have the following statement for 11g

    Select sum (A.Wert) of
    (
    with t as (select vtobslpos. RANK rank #, vtobslpos. ANZAHL count #, vtobsl.faellig f #, vtobslpos. PAYMENT vtobslpos wert, vtobsl
    where vtobslpos. SYSVTOBSL = vtobsl.sysid and vtobsl.inaktiv = 0 and vtobsl.sysvt = 165406
    )
    t1 as)
    Select rownum rn
    of the double
    connect by level < = (select sum (County #) t)
    )
    Select row_number() line (order of ranking #, rn) #, ranking #, 1 count, add_months (f #, row_number () (order of ranking #, rn)-1) Faellig, Wert
    t, t1
    where t1.rn < = t.count #.
    ) AT
    ' where A.Faellig > = ' 30.06.2011.
    ' - where A.Faellig between ' 30.06.2011 "and + 30 to_date('30.06.2011','dd.mm.yyyy')
    -where A.Faellig between to_date('30.06.2011','dd.mm.yyyy') and to_date('30.06.2011','dd.mm.yyyy') + 30, 90

    that works fine for all three, where the conditions used both. What I would like to have are the different results of the sum (A.Wert) of all three conditions

    "Condition 1: where A.Faellig > = ' 30.06.2011.
    "Condition 2: where A.Faellig between ' 30.06.2011" and + 30 to_date('30.06.2011','dd.mm.yyyy')
    Condition 3: where A.Faellig between to_date('30.06.2011','dd.mm.yyyy') and to_date('30.06.2011','dd.mm.yyyy') + 30, 90

    in a row without repeating the statement internal / virtual table (with t as...-...) One that provides a payment stream that is stored in a form that is compressed in the comic book as follows

    LINE # FAELLIG WERT
    1 15.10.2004 00:00:00 691,48
    15.11.2004 2 00:00:00 691,48
    15.12.2004 3 00:00:00 691,48
    4 15.01.2005 00:00:00 691,48
    15.02.2005 5 00:00:00 691,48
    15.03.2005 6 00:00:00 691,48
    15.04.2005 7 00:00:00 691,48
    15.05.2005 8 00:00:00 691,48
    15.06.2005 9 00:00:00 691,48
    15.07.2005 10 00:00:00 691,48
    15.08.2005 11 00:00:00 691,48
    15.09.2005 12 00:00:00 691,48
    15.10.2005 13 00:00:00 691,48
    15.11.2005 14 00:00:00 691,48
    15.12.2005 15 00:00:00 691,48
    15.01.2006 16 00:00:00 691,48
    15.02.2006 17 00:00:00 691,48
    15.03.2006 18 00:00:00 691,48
    15.04.2006 19 00:00:00 691,48
    15.05.2006 20 00:00:00 691,48
    15.06.2006 21 00:00:00 691,48
    15.07.2006 22 00:00:00 691,48
    15.08.2006 23 00:00:00 691,48
    15.09.2006 24 00:00:00 691,48
    15.10.2006 25 00:00:00 691,48
    15.11.2006 26 00:00:00 691,48
    15.12.2006 27 00:00:00 691,48
    15.01.2007 28 00:00:00 691,48
    15.02.2007 29 00:00:00 691,48
    15.03.2007 30 00:00:00 691,48
    15.04.2007 31 00:00:00 691,48
    32 15.05.2007 00:00:00 691,48
    33 15.06.2007 00:00:00 691,48
    34 15.07.2007 00:00:00 691,48
    35 15.08.2007 00:00:00 691,48
    36 15.09.2007 00:00:00 691,48
    37 15.10.2007 00:00:00 691,48
    38 15.11.2007 00:00:00 691,48
    39 15.12.2007 00:00:00 691,48
    40 15.01.2008 00:00:00 691,48
    41 15.02.2008 00:00:00 691,48
    42 15.03.2008 00:00:00 691,48
    43 15.04.2008 00:00:00 691,48
    44 15.05.2008 00:00:00 691,48
    45 15.06.2008 00:00:00 691,48
    46 15.07.2008 00:00:00 691,48
    47 15.08.2008 00:00:00 691,48
    48 15.09.2008 00:00:00 691,48
    49 15.10.2008 00:00:00 691,48
    50 15.11.2008 00:00:00 691,48
    51 15.12.2008 00:00:00 691,48
    52 15.01.2009 00:00:00 691,48
    53 15.02.2009 00:00:00 691,48
    54 15.03.2009 00:00:00 691,48
    55 15.04.2009 00:00:00 691,48
    56 15.05.2009 00:00:00 691,48
    57 15.06.2009 00:00:00 691,48
    58 15.07.2009 00:00:00 691,48
    59 15.08.2009 00:00:00 691,48
    60 15.09.2009 00:00:00 691,48
    61 15.10.2009 00:00:00 20000
    62 15.11.2009 00:00:00 1500
    63 15.12.2009 00:00:00 1500
    64 15.01.2010 00:00:00 1500
    65 15.02.2010 00:00:00 1500
    66 15.03.2010 00:00:00 1500
    67 15.04.2010 00:00:00 1500
    68 15.05.2010 00:00:00 1500
    69 15.06.2010 00:00:00 1500
    15.07.2010 70 00:00:00 1500
    71 15.08.2010 00:00:00 1500
    72 15.09.2010 00:00:00 1500
    73 15.10.2010 00:00:00 1500
    74 15.11.2010 00:00:00 1500
    75 15.12.2010 00:00:00 1500
    76 15.01.2011 00:00:00 1500
    00:00:00 77 15.02.2011 1500
    78 15.03.2011 00:00:00 1500
    79 15.04.2011 00:00:00 1500
    80 15.05.2011 00:00:00 1500
    81 15.06.2011 00:00:00 1500
    82 15.07.2011 00:00:00 1500
    83 15.08.2011 00:00:00 1500
    84 15.09.2011 00:00:00 1500
    85 15.10.2011 00:00:00 1500
    86 15.11.2011 00:00:00 1500
    87 15.12.2011 00:00:00 1500
    00:00:00 88 15.01.2012 1500
    00:00:00 89 15.02.2012 1500
    00:00:00 90 15.03.2012 1500
    00:00:00 91 15.04.2012 1500
    00:00:00 92 15.05.2012 1500
    93 15.06.2012 00:00:00 1500
    00:00:00 94 15.07.2012 1500
    95 15.08.2012 00:00:00 1500
    00:00:00 96 15.09.2012 1500
    97 15.10.2012 00:00:00 1500
    98 15.11.2012 00:00:00 1500
    99 15.12.2012 00:00:00 1500
    100 15.01.2013 00:00:00 1500
    101 15.02.2013 00:00:00 1500
    102 15.03.2013 00:00:00 1500
    00:00:00 103 15.04.2013 1500
    104 15.05.2013 00:00:00 1500
    105 15.06.2013 00:00:00 1500
    106 15.07.2013 00:00:00 1500
    107 15.08.2013 00:00:00 1500
    108 15.09.2013 00:00:00 1500
    109 15.10.2013 00:00:00 1500
    00:00:00 110 15.11.2013 1500
    111 15.12.2013 00:00:00 1500
    112 15.01.2014 00:00:00 1500
    113 15.02.2014 00:00:00 1500
    114 15.03.2014 00:00:00 1500
    115 15.04.2014 00:00:00 1500
    116 15.05.2014 00:00:00 1500
    117 15.06.2014 00:00:00 1500
    118 15.07.2014 00:00:00 1500
    119 15.08.2014 00:00:00 1500
    120 15.09.2014 00:00:00 1500
    121 15.10.2014 00:00:00 1500
    122 15.11.2014 00:00:00 64883,93

    Thanks a lot for any help
    Best regards
    Carsten

    Something like that...

    SELECT
    SUM( CASE WHEN condition1 THEN A.Wert ELSE 0 END ) AS sum1,
    SUM( CASE WHEN condition2 THEN A.Wert ELSE 0 END ) AS sum2,
    SUM( CASE WHEN condition3 THEN A.Wert ELSE 0 END ) AS sum3
    FROM
    (
    with t as
    ..
    ..
    ..
    -- Remove the three conditions from the WHERE clause
    

    -Rakesh

  • How can I add a donation page with different levels to give for example $ 250, $150, $50, other

    How can I add a donation page with different levels to give for example $ 250, $150, $50, other.  I'm with Foxy cart... is it possible?

    Since the end of the Muse, you can add texts as the value of the donation with paypal button that would take users to the paypal for the payment site, with Foxy cart you can try the suggestion mentioned here:

    https://Forum.FoxyCart.com/discussion/4417/donation-page-radio-button/P1

    Thank you

    Sanjit

  • How can I get the lines for the date between 2 different days

    Hi all,

    How can I get the lines for the date between 2 different days.

    Sample data:
    Table name: Articles
    Title start_date end_date
    Heading1 08-22-2011 2011-09-11
    2011-08-01-2011-09-01 Title2
    Title 3 2011-08-21 08-21-2011
    title4 2011-08-28 2011-09-11

    Result will be:
    Title start_date end_date
    Heading1 08-22-2011 2011-09-11
    2011-08-01-2011-09-01 Title2
    title4 2011-08-28 2011-09-11

    This is my example query:
    SELECT * FROM items WHERE trunc (es.date_start) > = TO_DATE('2011-08-22', 'YYYY-MM-DD') AND trunc (es.date_end) < = TO_DATE ('2011-08-28', 'YYYY-MM-DD')

    but I can not get the expected results. Any help would be much appreciated.

    Thanks in advance

    not read your question properly before...

    Please try this

    Select * FROM items
    WHERE (TO_DATE ('2011-08-22', 'YYYY-MM-DD') between TRUNC (es.date_start))
    AND TRUNC (es.date_end)) OR
    (TO_DATE ('2011-08-28', 'YYYY-MM-DD') between TRUNC (es.date_start))
    AND TRUNC (es.date_end))

  • Where are the best sites for high-level and how information to do different things in Oracle?


    Hello

    Where are the best sites for high-level and how information about various things in Oracle?

    Some examples of things:

    * spa

    * spm

    * db replay

    * Resource Manager

    I need a place high-level

    and also a place of step by step.

    For example, I look at these sites:

    www.Oracle-base.com

    www.psoug.org

    Thank you Roger

    Part of the problem is not so much finding sites that have articles on Oracle, that is to find reliable websites with this information.  When I search my site of certification for resources, I find a significant number of people who have 'technical' Articles on Oracle. However, many of these blog posts have simply no useful information.  It is not even that they are wrong so far as article does not include anything that is not declared more clearly and in detail in the documentation.

    That said, a site you have not mentioned above is the Oracle Learning Library.  There very often an excellent material that is very closely linked to the themes of the certification:

    https://apexapps.Oracle.com/pls/Apex/f?p=44785:1:0

  • How not to display no data found for two different elements

    I wanted to view report by dept wise or wise provider
    so when I'm not have associated deptno data
    It should say no data found
    for this I use if condition
    Ditto for the provider too
    instead of giving twice can I give it in the same condition if
    If so, how

    Use logical operator 'or '.

    as not found data

  • How to set the date limit for the whole process

    How to configure dynamically.
    For example, the date limit is different in each case and can be defined by a user so changed in the middle.

    Published by: YE may 6, 2009 18:09

    The deadline for the whole process is determined by what you set the variable preset 'deadline '. This interval can be set inside the process as soon as the activity to Begin.

    To set differently for different instances use a time interval variable or a parameter of the company. Here is an example. You have different levels (SLA) different service level agreements in the category of customers. Platinum level customers are 2 days, gold-level clients are 4 customer days silver are six days. In a method, you then have the logic:

    if customer.level = "Platinum" then
        // DEADLINE_HOURS_PLATINUM is an integer Business Parameter set initially to 2 days
        deadline = 'now'.addHours(i : DEADLINE_HOURS_PLATINUM)
    elseif customer.level = "Gold" then
        deadline = 'now'.addHours(i : DEADLINE_HOURS_GOLD)
    elseif customer.level = "Silver" then
        deadline = 'now'.addHours(i : DEADLINE_HOURS_SILVER)
    else
        // no deadline for the process
        deadline = null
    end
    

    If make you a business setting, a business owner could change later ALS a developer need to change the process and by redeploying the it.

    If you want to use an instance time interval variable instead to do this, the logic would be just:

    deadline = 'now' + someTimeIntervalVariable
    

    Hope this helps,
    Dan

  • How can I order a calendar with information for different countries

    In the past, I was able to create a calendar and then order different versions of information for different countries. I can't find this option now. It has been deleted? If this is not the case, how can I do?

    Hey oldcelt,.

    I understand that you want to add information to another country. Let's see what options are available for your calendar.

    You can view the holidays from a specific country. To do this, open the calendar in the calendar settings button settings button of the toolbar and you will see a section for "national holidays of the show. Make your selection and you will be ready to go. For more details, take a look at the information below.

    Change the date of a calendar information
    http://help.Apple.com/photos/Mac/1.1/#/phtb94d9019

    Change the date of a calendar information

    You can easily change the settings of date and your calendar at any time. You can also have your calendar displays events in your calendar application, the national holidays of many countries and anniversaries that you saved in Contacts.

    1. Click project on the toolbar, and then double-click the calendar.

    2. Click the calendar settings on the toolbar.

    3. Do one of the following:

      • Choose a fresh start, month, or year: Use the pop-up menus at the top of the settings pane.

      • Change the number of months in the calendar: Pick a number on the shortcut menu.

      • Display the national holidays of the country: Click the menu drop-down "show national holidays ' and choose the desired country. To stop the display of national holidays, choose None.

      • Display the calendar events: Check the box next to each calendar that you want to display.

        Note: The calendars that you see listed here are the ones you have set up in the calendar application on your Mac.

      • Show the birthdays you have saved in contacts: Select "show Contacts birthdays."

    Take it easy

  • Automation of loading the data of single application FDM for different applications

    Friends, my query is somewhat complex. I have 6 (two in Hyperion Planning, two HPCM) and two in Hyperion Essbase applications. I copied the adapter in the Workbench and renamed accordingly to load the data for each of them. Now the problem is I want to automate the data load for each of these requests, but don't know how it's done. Through many forums to get a better understanding but no luck!

    A humble request to all the FDQM experts for their valuable advice on how to realize the automation of all the tools in one application of FDM.

    Thanks in advance!

    You would automate this process via the Batch Loader integrated with FDM. The process to use this is exactly the same as you have one or more target applications. The ultimate target application is based on the name of the place incorporated into the batch processing file naming convention. Each of your adapters different target will be associated with one or more locations in your configuration of metadata location FDM.

  • How can I erase different levels of opacity of a color?

    I was thumbnail sketches using the Brush tool, in a single color (black) with different levels of opacity for the shading. I had milked on a single layer and on the other, but accidentally shaded shading on the line drawing and can no longer cancel/step back. I need to delete/remove shading and keep the intact black line drawing, but the PS does not seem be able to differentiate between the different levels of opacity and treats as a single colour when I try to use the erase special as Magic Eraser no matter how high I set the tolerance or selection tools, etc.. It's a simple sketch and I could draw it again, but I'm very rusty with PS and I would like to know if there is a solution in case I met this new. Prescheduled A below. Suggestions?

    Opacity.JPG

    Part three fix

    Levels adjustment layer and drag the slider of Pentecost slowly to the left.  This will gradually move the nuances that darkens the white full.  Move the black slider until it is in the fleshy part of the shadows (black) and adjust the slider to the Middle for the best effect.  You will fix with this step.  Just do a lot better.

    NOTE: you must change the blend mode of layer of brightness levels.

    I'd be inclined to remove all the colors of the image as well.  (Hue saturation, B & W adjustment layer, but do not change gray scale)

    Now select the layer levels and do a layer of copy merged top Ctrl Alt Shift (Shift Cmd Opt e) e

    Now select the brush, and then change the brush in overlay blending mode (in the options bar)

    Carefully paint on the black lines with black to strengthen and shading with white to remove it.  Need you a bit of practice.

    It took me about two minutes.  Another ten and you'll have it right, (assuming that the original is a higher resolution)

  • How to get LASTDAY for each month between data dates...

    Hi friend

    I have a doubt, how to get LASTDAY for each month between data dates...

    for ex:
    My contribution will be like this
    date = 01/12/2011
    To date = 14/04/2011

    And I need an output like
    31/01/2011
    28/02/2011
    31/03/2011

    is it possible to achieve through sql query in oracle
    Thanks in advance for all friends to help him

    Hello

    Something like this (assuming that the dates are originally VARCHAR2s):

    SQL> var dt_start varchar2(10)
    SQL> var dt_end varchar2(10)
    SQL> exec :dt_start := '12-01-2011'
    
    PL/SQL procedure successfully completed
    
    SQL> exec :dt_end := '14-04-2011'
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> select last_day(
      2           add_months(
      3             trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM'),
      4             level-1
      5           )
      6         ) as result
      7  from dual
      8  connect by level <= months_between(to_date(:dt_end,'DD-MM-YYYY'), to_date(:dt_start,'DD-MM-YYYY'))
      9  ;
    
    RESULT
    -----------
    31/01/2011
    28/02/2011
    31/03/2011
     
    

    If the dates are already of the date data type, simply remove the to_date function.

  • Export data to different levels

    Hello

    I am trying to automate pulling a report out of essbase. The Calc of data export creates a Level0 txt file that is difficult to validate against one online report from oracle. I'm pretty much wanting to pull all top-level except accounts whiich dimension must be at level 0, I can compare the balance in Oracle Hyperion. This must be an automated solution and I will use VBScript to run Oracle sql queries. Is it possible to pull a report at different levels in essbase maxl or any other form? I'm really not familiar with Hyperion reports. Is it possible to run a report of Hyperion via a script and do produce a txt file?

    I really appreciate any information on this and hope someone can help.

    Out the data is quite simple using a report script. In a script to report unspecified dimensions by default to the top of the dimension, so if that's really all you need (i.e. you have no dimension that do not consolidate the Summit or otherwise should be noted) something as minimalist as...

    {NOINDENTGEN}
    {SUPPAGEHEADING}

    !
    .. could actually be sufficient as the report script. Script editor for the report of the Administration Console allows to develop and test the script before trying to automate. Much better control the missing / zero suppression and substition, formatting, etc. is possible. The Builder of the technical documentation section is here: http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_tech_ref/frameset.htm?rw_commands_chap.html

    To integrate the report script in automation, you can watch the execution of the script of report using the MaxL "data export" command I'm assuming you can afford in your scenario. "export data" allow us you to specify a file for the output .txt. For more information, the MaxL in the technical reference section is here: http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_tech_ref/frameset.htm?maxl_chap.html.

  • How to have different font style for different tree node?

    Hello

    How can I have different font style for different tree node?

    for example,.

    Tree level1

    -Scale of the tree 2

    the level1 tree has 12 font size and tree level 2 has 22 font size.

    Thank you

    Set variableRowHeight = true on the tree.

    Subclass TreeItemRenderer, override the listData setter and change the fontSize based on the TreeListData.level.

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

Maybe you are looking for

  • macOS Sierra hangs after startup

    I have a macbook pro 15 inch mid 2014 retina After that I installed macos sierra my macbook freezes after startup for about 10 min before things become normal after shots completely from the OS, I tried the P + R command cmd startup items cleaning +

  • Cannot disconnect from iCloud

    I cannot disconnect iCloud on my iPhone, because I don't remember the password and can not be sent to my e-mail because I can't access it. Any ideas before go me crazy?

  • Satellite Pro L550 - Mute button no longer works

    I ran a few Toshiba and other updates on my Satellite L550 and now its secret key on the keyboard no longer works.Can someone help me? Kind regards Dirk

  • Unable to transfer data of Ms money on a new laptop

    Dear all I read your Article Money 2005 patches made available by Microsoft to http://money.mvps.org/faq/article/649.aspx thank you! Please help me: 1. I use Microsoft Money Deluxe Ver 14.0.120.1105 with serial No. / * personally identifiable informa

  • Error code: don't have 0x2B33 KB960082

    The KB above is 'updating security for SQL Server 2000 SP4'. Automatic updates successfully downloads and installs, but after a reboot, the Update icon reappears I always ask to install. Belarc Advisor lists this as lacking KB, it lists as "a securit