Using GROUP BY ROLL UP can I sum only certain levels?

I am using a group by rollup in the hope to add a grand total.
Here's an example
with mydata as (
select 'A' part_no, 'A Part' Description, '100' serial, 10 Qty, 45 unit_cost from dual
UNION ALL
select 'A' part_no, 'A Part' Description, '101' serial, 10 Qty, 45 unit_cost from dual
UNION ALL
select 'A' part_no, 'A Part' Description, '102' serial, 5 Qty, 46 unit_cost from dual
UNION ALL
select 'A' part_no, 'A Part' Description, '103' serial, 10 Qty, 45 unit_cost from dual
UNION ALL
select 'B' part_no, 'B Part' Description, '200' serial, 15 Qty, 10 unit_cost from dual
UNION ALL
select 'C' part_no, 'C Part' Description, '100' serial, 1 Qty, 100 unit_cost from dual
UNION ALL
select 'C' part_no, 'C Part' Description, '101' serial, 10 Qty, 95 unit_cost from dual
select
part_no,
description,
sum(qty) total_qty,
sum(qty*unit_cost) total_value
from mydata
group by
rollup(
part_no,
description)However, I only want a GRAND total, not subtotals.
I can use the clause at the end:
having
(grouping(part_no)=0 and grouping(description)=0)
or
(grouping(part_no)=1 and grouping(description)=1)But is there a simpler way?
I was using this kind of method in the past:
with mydata as (
select 'A' part_no, 'A Part' Description, '100' serial, 10 Qty, 45 unit_cost from dual
UNION ALL
select 'A' part_no, 'A Part' Description, '101' serial, 10 Qty, 45 unit_cost from dual
UNION ALL
select 'A' part_no, 'A Part' Description, '102' serial, 5 Qty, 46 unit_cost from dual
UNION ALL
select 'A' part_no, 'A Part' Description, '103' serial, 10 Qty, 45 unit_cost from dual
UNION ALL
select 'B' part_no, 'B Part' Description, '200' serial, 15 Qty, 10 unit_cost from dual
UNION ALL
select 'C' part_no, 'C Part' Description, '100' serial, 1 Qty, 100 unit_cost from dual
UNION ALL
select 'C' part_no, 'C Part' Description, '101' serial, 10 Qty, 95 unit_cost from dual
select
part_no,
description,
sum(qty) total_qty,
sum(qty*unit_cost) total_value
from
mydata
group by
part_no,
description
UNION ALL
select
null,
null,
sum(qty) total_qty,
sum(qty*unit_cost) total_value
from
mydataWhich is inefficient, especially over a lot of data. But isnt aggregating over never to be used levels inefficient too?
Thanks

Using Composite column:
SQL> with mydata as (
  2    select 'A' part_no, 'A Part' Description, '100' serial, 10 Qty, 45 unit_cost from dual
  3    UNION ALL
  4    select 'A' part_no, 'A Part' Description, '101' serial, 10 Qty, 45 unit_cost from dual
  5    UNION ALL
  6    select 'A' part_no, 'A Part' Description, '102' serial, 5 Qty, 46 unit_cost from dual
  7    UNION ALL
  8    select 'A' part_no, 'A Part' Description, '103' serial, 10 Qty, 45 unit_cost from dual
  9    UNION ALL
10    select 'B' part_no, 'B Part' Description, '200' serial, 15 Qty, 10 unit_cost from dual
11    UNION ALL
12    select 'C' part_no, 'C Part' Description, '100' serial, 1 Qty, 100 unit_cost from dual
13    UNION ALL
14    select 'C' part_no, 'C Part' Description, '101' serial, 10 Qty, 95 unit_cost from dual)
15  select part_no,description,sum(qty) total_qty,sum(qty*unit_cost) total_value
16  from mydata
17  group by rollup((part_no,description))
18  ;
P DESCRI  TOTAL_QTY TOTAL_VALUE
A A Part         35        1580
B B Part         15         150
C C Part         11        1050
                 61        2780Regards,
Dima

Similar Messages

  • Using Direct input method(LSMW)Can I upload only 3 fields for MM01

    Using Direct input method(LSMW)Can I upload only Matnr,mbrsh,mtart fields for MM01.Otherwise I have to give all the mandatory fields.?

    Hello TJK,
    LSMW will work in the same way as you create normal material master with the transactions, here you are giving the value through flat file and creating material master with program.
    You can create only one view with LSMW but you need to give all mandatory field on that particular view, so if you have only these three field as mandatory then yes it is possible, if you have any more field mandatory addition to these fields then it will not work out, during the last step it will throw error saying "maintain the value for field XXX"
    Hope this helps.
    Regards
    Arif Mansuri

  • I'm wanting to migrate certain applications from my MacBook Pro over to my newer Mini, but Migration Assistant doesn't allow doing this by choosing which applications to migrate-how can I pick only certain ones?

    I'm wanting to migrate certain applications from my MacBook Pro over to my newer Mini, but Migration Assistant doesn't allow doing this by choosing which applications to migrate-how can I pick only certain ones?

    You only bought it four months ago, so it's still under warrantly.
    Call Applecare or call your nearest Applestore to make an appointment. Tell them your mac has serious technical issues, describe them shortly.

  • Can't figure out how to sum only certain dates

    Hi all,
    Here is my issue: we use numbers to keep a running inventory of pieces in stock, and when a piece sells we mark it with the date sold. I'd love to be able to get a sum of monthly sales, but I can't figure it out. Would someone be kind enough to explain it to me like I was five? Here is a sample of our spreadsheet layout: http://i.imgur.com/sV1RU4s.png
    I can easily get a sum for the full column of C, but how do I enter the formula to sum only the sales from April, for instance.
    Thanks!!

    you can get function descriptions from Apple for free by downloading the function references here:
    http://support.apple.com/manuals/#productivitysoftware
    you will want to download the formula and function reference.
    OK...
    sumif() is a function that will sum values in a range based on a condition
    sumifs() is a similar function where multiple conditions
    both functions look at each row and only sum the values in a particular row when the condition(s) are all met.
    =SUMIFS(B,C,">="&E2,C,"<="&EOMONTH(E2, 0))
    let's work from the inside out...
    EOMONTH() returns the last day of the month you pass if offset by some number of months.  In this case I asked it to give the last day of the same month I passed in so the offset is 0.  The month I passed in is stored in E2.
    the basic concept is I only want to sum values in column B when the date in column C is in a paricular month.  said another way... I want to sum values in B where the corresponding date (in the same row) of column C is greater than or equal to the 1st day of the month AND is it also less than or equal to the last to of the month.
    SUMIFS() has several arguments a range to sum followed by a pair of arguments (test values range and a condition):
    SUMIFS(<SUM_RANGE>, <TEST_RANGE1>, <CONDITION1>, <TEST_RANGE2>, <CONDITION2>, etc )
    the sum range is column B
    test range 1 is the date column (column C)
    the condition is ">="&E1  which concatenates ">=" with the date in cell E1 to make a condition ">=Jan 1, 2013"
    test range 2 is the date column (column C)
    the condition is "<="&EOMONTH(E1, 0)  which concatenates "<=" with the date corresponding to the last day of the monthe in cell E1 to make a condition "<=Jan 31, 2013"
    I hope this helps

  • HT201250 I use time machine and I can't get a certain backup to allow restore

    My MBPro stopped booting up. I got it up and running again after reinstalling everything(OSX and all). I am now running Mountain Lion, could this be causing problems seeing all the non Mountain Lion era backups. I can only restore those dates now, no older than upgrade date ones.
    I hooked up my time machine drive and now I can't get a certain date to make itself available for "Restore" the latest date that lights up that button in Time Machine is the date I did the reinstall. How do I get my excel files I made back onto my computer.
    Other issue is where are Excel files kept in the MAC's file structure. I know the were backed up, but I can't see them when I am using Finder to look within each subfolder in Time Machine.

    Welcome to the Apple Support Communities
    When you turn on the new iMac for the first time, Setup Assistant will ask you to restore a backup, so connect the external disk and follow steps to restore all your files to your new iMac. Your new Mac will have the same settings and programs as your old computer.
    In other cases, I would recommend to restore the whole backup without using Migration Assistant or Setup Assistant, but a Late 2012 iMac uses a special OS X build, so the OS X version that you're using on your old Mac won't work on the new one. For more information, see > http://pondini.org/OSX/Home.html

  • I just purchased Aperture and have 20,000  photos in my iPhoto Library. Can I import only certain events from iPhoto into Aperture or do I have to merge the whole iPhoto library?

    I just purchased Aperture and have 20,000 + photos in my iPhoto Library. I see that I can create a unified library between the two. I am wondering if I can import only certain events from iPhoto (like only 2014 events) into Aperture or do I have to merge the whole iPhoto library? Are there any benefits to bringing the whole iPhoto library over to Aperture (iPhoto is SO SLOW for me, I wonder if it is because I have so many photos). Or, any detriment to only bring a few events over?
    And, if I don't merge the two libraries, I assume that means I cannot do it at a later date?
    Help. My local Apple store has had very few Aperture workshops, and the next one is like 2 months away.

    Thank you so much for this information. Here are some responses/comments:
    Disk space - it says 114.43 GB out of 499.25 GB free. I have no idea if that is enough.
    iPhoto version is 9.5.1
    Again, I am not sure how to know if I have 3rd party software...but I don't think I do. Is 3rd party software anything non-apple?
    I will try rebuilding the library. if that doesn't help, maybe I need more memory...? That is what Apple suggested, but that, of course, means buying something else. I've already bought APERTURE, on their recommendation...
    It wasn't, and they told me it was slow because I had too many photos for iPhoto to handle and that I should buy Aperture. Which I did.
    What is your iPhoto version? Are you using the most recent version 9.5.1?
    iPhoto can handle 20000 photos, no problem.  Your computer can be slow for several reasons:
    The most common problem for slowness - insufficient disk space. Don't let your free disk space drop below 20 GB of free space, better more. If the operating system does not have enough working space and the applications you are using, you will notice a very lagging behaviour.
    Older or incompatible softweare can cripple your mac. Do you have any older third-party software installed, that might have installed incompatible kernel extensions?
    Aperture might be slow or keep crashing, if you imported a corrupted image or incompatible video,  that cannot be processed. Then Aperture will try over and over again to create previews and never succeed.  You could test for this situation, by launching Aperture with the Shift-key held down. This will defer the generation of previews. If Aperture will launch and work better this way, you probably have some bad media in your photo library.
    Another problem to check for is a corruption of your Aperture/iPhoto library. You have run the First Aid Tools to repair the iPhoto Library, but have you ever tried to rebuild the library? See this post by Old Toad: Rebuild iPhoto Version 11

  • After back up, can i choose only certain files to restore?

    I am currently backing up my entire Macbook so i can reinstall Leopard. I was wondering after the reinstallation of Leopard if i can be able to choose only certain files like my music, pictures, ETC? Because i would like to start to use the root account.

    As Duane has mentioned, you will be able to access Time Machine backups from your computer by setting Time Machine up again and choosing your Time Capsule as the backup disk. You will need your TC disk password as well.
    I think I recall a user who said he could not access his backups after reinstalling the operating system on his machine. He couldn't remember the TC password and...he could not go back into KeyChain Access to try to retrieve his password because the application had been reinstalled, erasing the old stored data. Keep your TC password in a safe place as you will not be able to access the TC without it.
    In the event that you are having difficulty with restoring Time Machine backups, you also have the ability to use Migration Assistant to move files back from the TC to your computer. You will need your TC password to do this as well. You won't be able to selectively choose just the files you want to move, but you can always go back into your hard drive and delete the files that you don't want or need.

  • Can I sum only the top 10 values in a range?

    I am new to mac and numbers.  I bought my first mac this fall.  I have a grade book in Numbers.  I am only counting the top 10 out of 11 homework scores and top 10 out of 13 quiz scores.
    Essentially, I want to add the top K values out of a range of N cells.  Can I do this?
    Thanks.

    you can use the large() function like this:
    C1=AVERAGE(LARGE(B,1), LARGE(B,2), LARGE(B,3), LARGE(B,4), LARGE(B,5), LARGE(B,6), LARGE(B,7), LARGE(B,8), LARGE(B,9), LARGE(B,10))
    this is shorthand for... select cell C1, then type (or copy and paste from here) the formula:
    =AVERAGE(LARGE(B,1), LARGE(B,2), LARGE(B,3), LARGE(B,4), LARGE(B,5), LARGE(B,6), LARGE(B,7), LARGE(B,8), LARGE(B,9), LARGE(B,10))

  • Can you select only certain email folders to show up in Thunderbird?

    We use shared folders between proxy users. We have records requests and need a faster way to provide the request to the citizen who is requesting the information. Thunderbird is a work around so we can easily forward the information that is in one folder. We would like to know if there is a way to only sync up with the one designated folder or if we have sync the entire email account.

    right click the account and select settings.
    Under server setting select advanced and select only show subscribed folders.
    Right click the account again
    Select subscribe and subscribe to only the folder/s you want to see.
    To make things faster you can also go to the synchronization and storage settings section in account settings and deselect the keep messages for this account on this computer. This will cause only the header information to compile the mail list to be downloaded and the message body will be fetched on demand. This will reduce traffic on the network as the messages will not be downloaded to each user, unless they are needed for viewing, printing forwarding et cetera.

  • How can i print only certain cells

    I'm trying to print just a portion of my large spreadsheet.  Is there a way I can only print, for instance, Cells A45 through F96?
    Thank you SO MUCH in advance!
    John

    Hi John,
    I'll agree with Barry on the easiest method...
    Select
    Command-C
    Preview
    Command-N
    Command-P
    Return
    A more sophisticated approach that you might prefer if your printout needs some annotation beyond the contents of the selected range or if you want to add some graphic touches, is the following:
    Select your Cells requiring Printing and Command-C.
    Insert > Sheet and Delete the empty default Table from the New Sheet.
    Edit > Paste Values to Paste your Selected Table segment from the original Sheet to the new Sheet.
    Option-Command-P to Show Print View in your new Sheet.
    Now you can assign Header and Footer Columns and Rows to your copied data, add data descriptions, position things the way you like, etc. Then Command-P, Return.
    Jerry

  • Is there a way where I can back up only certain stuff to iCloud

    I have a lot of photos on my iPhone and I want to be able to back up my photos to my computer instead but still be able to back up contacts, calenders, ect to iCloud.Is there a way to assign certain stuff to backup to iCloud and still have my photos be backed up to my computer?

    on your iphone go to icloud and untick photostream.
    now you can choose between back up automatically to the cloud or to itunes. if you still choose tou back up to the cloud (which has nothign to do with sync on the cloud), you can still back up via itunes, just secondary click on your iphone>backup.
    notice: you can always back up BOTH ways, but only one of them will be automatic.

  • Can you export only certain dates or events?

    I use iCal on my laptop to organize my life, but my job wants me to be on Oracle too. So I export my iCal "work" calendar and import it in Oracle. Fine. But then I add something to my calendar, and I want to put it on Oracle too. if I export my "work" calendar again, and import it on Oracle, now I've got one new event and duplicates of every other event I imported the first time.
    Is there a way to export my iCal calendar for only a range of dates? Or only this or that event? The ideal would be to be able to export everything added since the last export, but I don't see anything like that in the options.
    help -- this seems like an obvious and necessary feature, and I'm sure I'm just missing how to do it...

    HI,
    Did you ever determine an answer to this question? I really need to export data after a certain date... (I would also like to publish a calendar, after a certain date-- as no one needs to see the "old" events).
    Stu

  • How can I get only certain tabs' submenus to display?

    I only want the one tab on my nav bar to display its sub menus when hovering over it but I can only seem to get all or nothing kind of deal. Any assistane here would be nice! Thanks!

    Hello,
    Do you mean you want to create child pages for other top level pages, but not have them displayed for the visitors in the front end of the site? You may want to not make them as child pages and have them as separate top level pages as well. Or you may also want to keep them as is, but not export them (by disabling the 'export page' option) and those pages won't be exported/published at all.
    Cheers
    Parikshit

  • How can I sync only certain apps after a restore instead of all of them?

    I've been serisouly frustrated with iTunes trying to find a way to sync only the apps I want to sync. But iTunes insists that I sync every single app I have downloaded in the past to my phone and I don't want all of them on there. Now after restoring I have a bunch of apps on my phone waiting to sync and now have to either restore again or individually delete all 155 of them. Are there certain settings I'm missing here?  Please help!!

    Thanks for the help I did not receive
    Hey, glad I didn't help.
    I mean, you waited a whole 38 minutes for someone to volunteer their assistance.
    FYI:
    Select the iPhone in iTunes.
    Click the Apps tab.
    Click Sync apps and tick the apps you want to sync.
    Click Apply at bottom.
    You're welcome.
    After literally digging for forever.
    Something less than 38 minutes is forever? (time it took to post first question, find answer, get upset and post 2nd time).
    Oh, and thanks for posting how you resolved the issue so others (who may not get an immediate reply) will know how to solve a similar issue without getting upset.

  • How to Get ZERO and Non-ZERO Values in rowcount using Group by?

    Dear All,
    How can I get Non-ZERO and ZERO row count values in SQL using Group by? I can get non-zero values but when I want NULL should be returned to non-zero values it is ignoring ZERO values in output?
    Any hint?
    Thanks
    GQ

    Hi,
    Something like
    select count(case col
                    when 0
                    then 1
                  end) zero_count,
           count(case nvl(col,1)
                    when 0
                    then null
                    else 1
                  end) nonzero_countRegards
    Peter

Maybe you are looking for