How to make a summary on one level of the query

Hi
I have the following table relationship
Father -< Child -< GrandChild
Every table has numeric values that I would like to summarize but I have only one query:
select ...
from Father, Child, GrandChild
where Father.id = Child.parentId(+) and
Child.id = GrandChild.parentId(+)
In this query I would like to summarize values from Child and GrandChild. But if I summarize Child values they will be repeated depending on the number of GrandChild he has. So is there a way to do a "SUM" that will only summarize the values in Child without values repeating? SUM DISTINCT will not work because I can have values in two Childs that are equal.
Regards,
Néstor Boscán

Hi,
You should give sample data and expected result. Without that I can only guess what you want.
My guess is this:
with father as
select 1 f_id, 'f1' f_name from dual union all
select 2 f_id, 'f2' f_name from dual union all
select 3 f_id, 'f3' f_name from dual union all
select 4 f_id, 'f4' f_name from dual
,child as
select 11 c_id, 'c11' c_name, 1 parentid from dual union all
select 12 c_id, 'c12' c_name, 1 parentid from dual union all
select 13 c_id, 'c13' c_name, 2 parentid from dual union all
select 14 c_id, 'c14' c_name, 3 parentid from dual union all
select 15 c_id, 'c15' c_name, 4 parentid from dual union all
select 16 c_id, 'c16' c_name, 4 parentid from dual
,GrandChild as
select 101 gc_id, 'gc101' gc_name, 11 parentid ,1 age from dual union all
select 102 gc_id, 'gc102' gc_name, 11 parentid ,2 age from dual union all
select 103 gc_id, 'gc103' gc_name, 12 parentid ,4 age from dual union all
select 104 gc_id, 'gc104' gc_name, 12 parentid ,8 age from dual union all
select 105 gc_id, 'gc105' gc_name, 11 parentid ,16 age from dual union all
select 106 gc_id, 'gc106' gc_name, 14 parentid ,32 age from dual union all
select 107 gc_id, 'gc107' gc_name, 13 parentid ,64 age from dual
SELECT
     f_name
     ,case grouping_id(f_name, c_name) when 0 then c_name else 'All Childeren' end c_name
     ,case grouping_id(f_name, c_name, gc_name)  when 0 then gc_name else 'All grand Children' end gc_name
     ,sum(age)
FROM
     Father
, Child
, GrandChild
WHERE
     Father.f_id    = Child.parentId(+)
     AND Child.c_id = GrandChild.parentId(+)
group by
grouping sets
          (f_name, c_name, gc_name)
          ,(f_name, c_name)
          ,(f_name)
F_NAME C_NAME        GC_NAME            SUM(AGE)
f1     c11           gc101                     1
f1     c11           gc102                     2
f1     c11           gc105                    16
f1     c11           All grand Children       19
f1     c12           gc103                     4
f1     c12           gc104                     8
f1     c12           All grand Children       12
f1     All Childeren All grand Children       31
f2     c13           gc107                    64
f2     c13           All grand Children       64
f2     All Childeren All grand Children       64
f3     c14           gc106                    32
f3     c14           All grand Children       32
f3     All Childeren All grand Children       32
f4     c15                                      
f4     c15           All grand Children         
f4     c16                                      
f4     c16           All grand Children         
f4     All Childeren All grand Children         
19 rows selected Regards,
Peter

Similar Messages

  • Hi , How to make a calculated kf as local in the query definition

    Hi ,
    How to make a calculated kf as local in the query definition
    Regards,
    Ravi.

    Hi,
    Calculate KF consists of Basic, restrict and other calculated kFs stored in Metadata repository.
    Calculate KF is a replicate of Formula and acts as Global.
    Calculate KF acts as Global--you can use Globally.
    Formula as Local--you can use as local to Query.
    you can create the Calculate KF as follow:
    Goto Query Designer>Open/Create Query>Select Key Figures Mode on left side of Query>Select that KF node> right click Select Calculate Keyfigure.
    then one popup window dispays, so you make the calculations based on Basic KF, Restirct Kf and Formule. then save it.
    Regards,
    Suman.

  • How to make swatches persistent from one document to the next?

    I want to have a custom swatches in my  workspace each time I open a document. How can I make swatches persistent in InDesign?

    You can have swatches available in new documents if you make them part of your defaults by loading them while no document is open, but there is no way that I know of to open any existing document that doesn't have a particular swatch and have that particular swatch available without loading it yourself. Probably the quickest way to load them into existing documents would be to:
    Make a frame
    Fill it with a swatch
    Repeat steps 1 & 2 until you have a frame for each swatch you want to transfer
    Grab all of the frames and drag them together into a library as one entry
    When you open a file, drag the frames from the library to the doc and immediately delete them while they are still selected. All of the swatches will have been added to your swatches list, and it's a little quicker than going to the swatches fly-out, selecting Load Swatches and navigating to a file that has the swatches saved in it, but that's another way if you prefer.

  • How do I get a Up One Level in the Topics page of my screen layout?

    I am trying to insert an "Up One Screen" on my Topic page in my screen layouts and it's only allowing me to add a hyperlink to the Table of Contents. Any suggestions?

    What do you mean by Up One Screen? Where is Rh only allowing you to add a hyperlink to the TOC?
    What sort of help are you generating?
    What version of Rh are you using?
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • How To Make Printer Only Use One Color From the Cartridge?

    Several weeks ago I had accidetnally found the settings, and now can not for the life of me find it. I want to make the default settings of the printer to only print in blue, so It only uses blue from the ink and will only print blue stuff. Its a multi colored image, and only want it to print the blue. its not just text i can change to blue.  Any ideas, I checked the printer properties and preferences, cant find it. I have a MG3120 and windows 8

    Hello. Please try the following steps to adjust the color settings: 1. Close all programs that are open.2. Click Start and open the Control Panel.3. Open Printers or Devices and Printers.4. Right-click the MG3100 and choose Printing Preferences.5. In the Main tab, change the Color/Intensity to Manual.  Then click Set. Once there, you can adjust the color settings as desired. This didn't answer your question or issue or need additional assistance? Find more help at Contact Us.  

  • Keyword management - how do you move keywords up one level?

    How do you move keywords up one level in the hierarchy? Sometimes when working quickly, keywords and subgroups of keywords get inadvertently highlighted and moved as a child under another keyword or group. I can't figure out how to move them back out again to the root level.

    I can't figure out how to move them back out again to the root level.
    You can drag and drop sub keywords to other locations higher or lower in the nested folder but you don't seem able to drag from sub level to root level.
    The easiest workaround would be to have a regular Back up of the list (pop menu from icon top right keyword panel: export keywords) and when not having added new words just use clear and import the back up to restore.
    If you did edit the list you can choose to export current list and with a simple text editor make the changes for keywords and sub keywords you want, save and then use again clear and import to retrieve the correct list.

  • How to make several pushbuttons in one line (on screen)??

    How to make several pushbuttons in one line (on screen)??
    thanks in advance!!!!

    Hi,
    USE
    SELECTION-SCREEN BEGIN OF BLOCK.
    SELECTION-SCREEN BEGIN OF LINE.
    define all buttons between this block.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK.
    selection-screen
    Cheers
    VJ

  • How to make data flow from one application to other in BPEL.

    Hi All,
    I am designing work-flow of my application through BPEL(JDeveloper), I am making different BPEL projects for different functions, like sales manager got the order from sales person and sales manager either approve it or reject it, if he approve it it goes to Production manager and he ships the goods, now I want to keep sales person, sales manger,production manager in seperate BPEL files and want to get the output of sales person to sales manager and sales manager to production manager please help me in dong this.
    I was trying to make partner link in Sales manager of sales person and getting the input from there. I dont know this is right even or not, if it is right I dont know how to make data flow from one application to other.
    Experience people please guide.
    Sales Person -----> Sales Manager ----> Production Manager
    Thanks
    Yatan

    Yes you can do this.
    If you each integration point to be in different process, you have to create three BPEL process.
    1. Create a Async BPEL process 'A' which will be initiated when sales person creates the order.
    2. From BPEL process 'A' call a ASync BPEL process 'B' which has the approval flow. Depending on the input from process 'A' the sales manager will review the order in workflow and approve or reject and send the result back to process 'A'.
    3. Based on the result from workflow, invoke the Sync BPEL process 'C', where you can implement the shipping logic.
    -Ramana.

  • How to make a summary column appear only once (in the first page only) in SSRS 2008?

    Hello Everyone,
    How to make a summary column appear only once (in the first page only) in SSRS 2008?
    Regards
    Gautam S
    Regards

    Hi,
    Assuming you have test data like this ;
    select 'abc'as [GROUP],'NN' name , 1 id
    union all
    select 'abc' as [GROUP] ,'PP' name , 1 id
    union all
    select 'abc'as [GROUP],'RR' name , 2 id
    Step1  : take Tablix with row group as your group Name .
    Step2 : right Click on Row Group Details -> Delete-> Delete Group Only
    Step3 : In Count Cell use below expression ;
    =CountDistinct(Fields!id.Value)
    Follow this link;
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b6b45917-0a26-4d15-be46-2c6a2697d6e9/distinct-rows-sum?forum=sqlreportingservices#5ffdee06-c2c8-44ea-a3a5-b958488bb6b5
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • I have a 120gb Classic that has no space left on it. i am going to buy a larger gb capacity ipod as soon as i get clearer instruction on how to get the old ipod content to the new ipod. How do you get content from one ipod to the other?

    how do you get content from one ipod to the new one? my content is on an external hard drive not on my pc and i have run out of space on my 120gb classic. can you get old ipod content to new? my itunes has only got short cuts, the real content is on an external drive? can this be done?? please help

    If the content is on an external drive, but your library knows where to find it, then it should all work. Connect your device, make some selections for what to put on it, and sync. If, on the other hand, your current iPod is the only place holding some of your media then see this user tip: Recover your iTunes library from your iPod or iOS device.
    tt2

  • How to make use of adjacent data elements within the same buffer

    Hi,
             Does anyone know how to make use of adjacent data elements within the same buffer? To make my question clearly, I would like to give you an example. In my application, I set "sample to read" as 10 which means at each loop 10 data samples will be taken into a buffer. Now, what I would like to do is to do some calculations on adjacent data samples in same buffer. I tried to use "shift register" for this, but it seemed to me that it only can deal with the calculation between data from adjacent loops. In other words, it skips 9 data elements and take the 10th one for the calculation.
             Here I also attach my VI showing what I did.
        Thank you very much in advance,
                            Suksun
    Attachments:
    wheel_encoder_1.vi ‏98 KB

    Hi Suksun,
          I hope you'll forgive me for distilling your code - mainly to understand it better.  I tried to duplicate your logic exactly - which required reversing the "derivatives"-array before concatination with the current samples array.  As in your code, the last velocity is being paired with the first position.  If first velocity is really supposed to be paired with first position, just remove the "Reverse 1D Array" node.
    cheers
    Message Edited by Dynamik on 01-07-2006 03:17 AM
    Message Edited by Dynamik on 01-07-2006 03:19 AM
    When they give imbeciles handicap-parking, I won't have so far to walk!
    Attachments:
    encoder2.GIF ‏14 KB
    encoder2.vi ‏102 KB

  • How to make ENTER key in internet explorer run the  BIP report?

    In BI publisher 11g, users wanted that after entering the values for the parameter, they hit the ENTER key ( on the keyboard)  and the report should run .
    In Mozilla firefox, when I hit ENTER key on the keyboard report runs fine... but in Internet explorer, it does not ( infact in internet explorer TAB key works)
    How to make ENTER key in internet explorer run the report?
    Thanks
    Ashish

    Perform the following steps and tell us if it  resolve this issue:
    1. In Internet Explorer, click Tools, and then click Internet Options.
    2. Click the Security tab.
    3. There are four security zones listed:
    * Internet
    * Local intranet
    * Trusted sites
    * Restricted sites
    Click the zone being used by P6, which is noted at the bottom right hand corner of the browser window when the P6 URL is being accessed.
    4. Under Security level for this zone, click Custom Level.
    5. Under Downloads, under Automatic prompting for file downloads, click Enable, and then click OK two times.
    6. The browser will need to be restarted for the change to take effect.
    Refer to the following Microsoft Knowledge base article for additional file download and active x controls which should also be enabled: http://support.microsoft.com/kb/883255

  • How can I move apps from one computer to the other?

    How can I move apps from one computer to the other?
    (preferably without iCloud)

    Backup your iTunes library to an external drive and onto the other computer
    http://support.apple.com/kb/ht1751

  • How do i copy stickies from one mac to the other

    how do i copy stickies from one mac to the other?
    or are they stored in a file i can just copy them over ? if so what is the file name path?
    thanks in advance

    yes, they are stored in the file /users/username/library/StickiesDatabase. just copy it over to the corresponding location on the new computer.

  • When I use Home sharing, I can see the library I want to copy, but when I highlight the library, the import button does not show up. Also, it will not let me drop and drag. How do I get music from one computer to the other computer?

    When I use Home Sharing, I can see the library I want to copy under Shared, but I can't get it save on the computer under the regular library. I go to edit and "select all" but there is no import button that is in the right hand corner. Also, it will not let me click and drag the music. How do I get it from one computer to the other?

    Since both computers are connected via the network, you could simply copy the ENTIRE iTunes folder from one computer to another via the network.
    If both computers are running Windows, use the Easy File Transfer Utility built into Windows to move iTunes and all other user media/data.

Maybe you are looking for