Getting top 9, aggregating the rest - challenge with SUM

Dear,
I'd like to get the top 9 customers and aggregate the remaining to one number.
My query is:
select k.kundenid, k.KDNR, k.FIRMA_1, sum(a.auftrag_total)
from auftrag a, kunden k
where a.kunde_id=k.kundenid and
TO_CHAR(a.DATUM,'YYYY')=TO_CHAR(sysdate,'YYYY')
group by k.kundenid, k.KDNR, k.FIRMA_1
order by 4 desc
I have tried with DENSE_RANK() but it gets complicated to combine this with SUM()
Can someone help?
Kind regards..........Lorenz

I seem to have hit a bug in XE on windows XP. The following query should work but the 10th record only includes the 10th ranked total, not the total of 10 thru 16.
If I change the with statement to a create table, the query works. Also, if I just use the second half of the union all I get the correct results. The combination of with and union/union all seems to fail.
create table auftrag(kunde_id number, kdnr varchar2(20), datum date, auftrag_total number);
insert into auftrag (select 1  kunde_id, 'cust1'  kdnr, sysdate datum, 1200 auftrag_total from dual);
insert into auftrag (select 1  kunde_id, 'cust1'  kdnr, sysdate datum, 600  auftrag_total from dual);
insert into auftrag (select 2  kunde_id, 'cust2'  kdnr, sysdate datum, 1600 auftrag_total from dual);
insert into auftrag (select 2  kunde_id, 'cust2'  kdnr, sysdate datum, 700  auftrag_total from dual);
insert into auftrag (select 3  kunde_id, 'cust3'  kdnr, sysdate datum, 500  auftrag_total from dual);
insert into auftrag (select 3  kunde_id, 'cust3'  kdnr, sysdate datum, 1300 auftrag_total from dual);
insert into auftrag (select 4  kunde_id, 'cust4'  kdnr, sysdate datum, 200  auftrag_total from dual);
insert into auftrag (select 5  kunde_id, 'cust5'  kdnr, sysdate datum, 1500 auftrag_total from dual);
insert into auftrag (select 6  kunde_id, 'cust6'  kdnr, sysdate datum, 800  auftrag_total from dual);
insert into auftrag (select 7  kunde_id, 'cust7'  kdnr, sysdate datum, 1400 auftrag_total from dual);
insert into auftrag (select 8  kunde_id, 'cust8'  kdnr, sysdate datum, 300  auftrag_total from dual);
insert into auftrag (select 9  kunde_id, 'cust9'  kdnr, sysdate datum, 2000 auftrag_total from dual);
insert into auftrag (select 10 kunde_id, 'cust10' kdnr, sysdate datum, 1900 auftrag_total from dual);
insert into auftrag (select 11 kunde_id, 'cust11' kdnr, sysdate datum, 400  auftrag_total from dual);
insert into auftrag (select 12 kunde_id, 'cust12' kdnr, sysdate datum, 1800 auftrag_total from dual);
insert into auftrag (select 13 kunde_id, 'cust13' kdnr, sysdate datum, 900  auftrag_total from dual);
insert into auftrag (select 14 kunde_id, 'cust14' kdnr, sysdate datum, 1000 auftrag_total from dual);
insert into auftrag (select 15 kunde_id, 'cust15' kdnr, sysdate datum, 1700 auftrag_total from dual);
insert into auftrag (select 16 kunde_id, 'cust16' kdnr, sysdate datum, 100  auftrag_total from dual);
create table kunden(kundenid number, firma_1 varchar2(20));  
insert into kunden (select 1  kundenid, 'desc1'  firma_1 from dual);
insert into kunden (select 2  kundenid, 'desc2'  firma_1 from dual);
insert into kunden (select 3  kundenid, 'desc3'  firma_1 from dual);
insert into kunden (select 4  kundenid, 'desc4'  firma_1 from dual);
insert into kunden (select 5  kundenid, 'desc5'  firma_1 from dual);
insert into kunden (select 6  kundenid, 'desc6'  firma_1 from dual);
insert into kunden (select 7  kundenid, 'desc7'  firma_1 from dual);
insert into kunden (select 8  kundenid, 'desc8'  firma_1 from dual);
insert into kunden (select 9  kundenid, 'desc9'  firma_1 from dual);
insert into kunden (select 10 kundenid, 'desc10' firma_1 from dual);
insert into kunden (select 11 kundenid, 'desc11' firma_1 from dual);
insert into kunden (select 12 kundenid, 'desc12' firma_1 from dual);
insert into kunden (select 13 kundenid, 'desc13' firma_1 from dual);
insert into kunden (select 14 kundenid, 'desc14' firma_1 from dual);
insert into kunden (select 15 kundenid, 'desc15' firma_1 from dual);
insert into kunden (select 16 kundenid, 'desc16' firma_1 from dual);
commit;
with t_rank as (
   select to_char(kunde_id) kunde_id, kdnr, firma_1, sum(auftrag_total) sum_at,
      row_number() over (order by sum(auftrag_total) desc) rn
   from auftrag, kunden
   where kunde_id = kundenid
   and trunc(datum,'y') = trunc(sysdate,'y')
   group by kunde_id, kdnr, firma_1)     
select *
from t_rank
where rn <= 9
union all
select 'Rest', 'Rest', 'Rest', sum(sum_at), 10
from t_rank
where rn > 9
order by 5

Similar Messages

  • I bought a movie on iTunes and it plays half the movie and stops. I can not get it to play after it stops. What can I do to get it to play the rest of the movie?

    I bought a movie on iTunes and it plays half the movie and stops. I can not get it to play after it stops. What can I do to get it to play the rest of the movie?

    Hi, Jjenjen30. 
    Thanks for the question and I believe we have a solution.  The best option would be to delete the movie that is giving you an issue and redownload it via the iTunes store past purchase option.  I have included a couple articles that will show you how to process these steps.
    Deleting files from the iTunes library and your computer
    http://support.apple.com/kb/ht3842
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/ht2519
    If this does not resolve the issue, then iTunes might need to be notified to let them know there is a problem with the content.  I have included the steps on how to let them know.
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
    http://support.apple.com/kb/HT1933
    Cheers,
    Jason H.

  • I am having a issue installing Adobe Acrobat XI.  I am running Windows 8.1. When  go to install it gets an error.  The error is with transform in registry and will not install product. I am looking at how I can fix this registry problem.

    I am having a issue installing Adobe Acrobat XI.  I am running Windows 8.1. When  go to install it gets an error.  The error is with transform in registry and will not install product. I am looking at how I can fix this registry problem.
    I have tried to uninstall all Abode Acrobat installations but one file remains and refuses to be uninstalled. It gives me this error : Error applying Transforms . Verify that specified paths are valid. It was installed on Sept 18 2014.  I have downloaded a Transform update but it tells I do not have a Adobe Acrobat product installed. 

    Hi all,
    Sylonious, did you manage to sort this problem out? I have been experiencing similar problems. I think my problem was because I had many different versions of JDKs. I have done a complete re-install. I would be really grateful to you (and anyone else) for help with this problem.
    I have re-installed JSDK1.4.2_03, set the "path" variable to "C:\JSDK1.4.2_03".
    When I compile using "javac" I get an error saying "javac" is not recognised.
    When I compile using "C:\j2sdk1.4.2_03\bin\javac Freq.java" no error is thrown.
    Every time I try to run a java file, I always get the NoClassDefFound error. When run with the -verbose option, files are loaded from C:\Program Files\Java\j2re1.4.2_03\bin - is this correct?
    I have removed all previous references to java in the registry editor.
    Please help !
    Regards,
    Vipul

  • TS1717 I just downloaded a song and it only plays the first 50 seconds and then moves to the next song in the list. How can I get it to play the rest of the song?

    I just downloaded a song and it only plays the first 50 seconds and then moves to the next song in the list. How can I get it to play the rest of the song?

    If your country's iTunes Store allows you to redownload purchased tracks, I'd delete your current copy of the track and try redownloading a fresh one. See the following document for instructions:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    Otherwise, I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the item that is not playing properly. If you can't see "Report a Problem" next to the item, click the "Report a problem" button. Now click the "Report a Problem" link next to the item.

  • Im having trouble getting my macbook pro to boot up after a fail safe boot, im getting as far as the grey screen with the apple loggo. so im trying to run a disk repair but is saying the disk is locked, how do i unlock disk??

    Im having trouble getting my macbook pro to boot up after a fail safe boot, im getting as far as the grey screen with the apple loggo. so im trying to run a disk repair but is saying the disk is locked, how do i unlock disk??

    Some clarification may help.
    You say you cannot boot normally.  It shows a gray screen with the Apple logo.
    Did you say it will boot successfully in Safe Mode (boot, then hold down the Shift key)?
    How did you boot the machine to run Disk Utility?  (Which keyboard combinations)?

  • I BOUGHT LIGHTROOM 5 IN LAREDO TX AND I TRIED TO GET IN MONTERREY MEXICO THE SERIAL NUMBER WITH THE REDEMPTION CODE BUT APPEARS AN ERROR. MY PC IS WINDOWS 8. COULD SOMEBODY HELP ME?

    I BOUGHT LIGHTROOM 5 IN BEST BUY LAREDO TX AND I TRIED TO GET IN MONTERREY MEXICO THE SERIAL NUMER WITH THE REDEMPTION CODE FROM THE BOX, BUT APPEARS AN ERROR. MY PC IS WINDOWS 8, COULD SOMEBODY HELP ME??

    I don't know that you can purchase Adobe software in the US for installing and using outside of the US.
    Redemption Code Help
    http://helpx.adobe.com/x-productkb/global/redemption-code-help.html
    Serial number and activation chat support (non-CC)
    http://helpx.adobe.com/x-productkb/global/service1.html ( http://adobe.ly/1aYjbSC )

  • I keep getting error 586 in the console along with the following: 3/18/12 7:55:19 PM com.apple.launchd[1] (org.samba.smbd) Throttling respawn: Will start in 10 seconds  3/18/12 7:55:29 PM com.apple.launchd[1] (org.samba.smbd[1246]) Exited with exit code:

    I keep getting error 586 in the console along with the following:
    3/18/12 7:55:19 PM com.apple.launchd[1] (org.samba.smbd) Throttling respawn: Will start in 10 seconds  3/18/12 7:55:29 PM com.apple.launchd[1] (org.samba.smbd[1246]) Exited with exit code:
    The console shows thousands of these error messages and it's messed up many functions of my MacBook.
    I have VMFusion on my Mac because for work I need to use Windows.  Last night I tried installing Windows 7 but could not complete installation.  I got a message saying "can not locate driver".  Then I started getting the Error 586.
    Today I unistalled VMFusion hoping that would resolve the Error 586.  No such luck.
    Can anyone help me get rid of this constant error, plesase?

    I believe this has something to do with Mail. Are these frequently occurring errors? If so and you quit Mail do the errors cease?
    Google searching for "org.postfix.master" reveals quite a number of links that you might check for more information.

  • HT1725 Hi, I'm pretty new to itunes. I bought a song and it downloaded, but will only play the first 3 seconds? Any idea how I get it to play the rest of the tune?

    Hi, I'm pretty new to itunes. I bought a song and it downloaded, but will only play the first 3 seconds? Any idea how I get it to play the rest of the tune?

    I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the item that is not playing properly. If you can't see "Report a Problem" next to the entry, click the "Report a problem" button. Now click the "Report a Problem" link next to the item.
    (Not entirely sure what happens after you click that link, but fingers crossed it should be relatively straightforward.)

  • Old computer crashed can i get my songs on the new one with out buying them

    my old computer's mother board went out and it wont turn on now, so i was wondering if there is anyway to get my old itunes songs on the new computer with out having to buy them all over i havn't tryed anything yet so i was just wondering if anyone had any answers. thanks

    If the motherboard crashed, the hard drive might still be OK. You can put the hard drive in an external USB hard drive enclosure for about $25. ll your music should still be on it!
    http://www.google.com/search?client=safari&rls=en&q=harddrive+intoenclosure&ie=UTF-8&oe=UTF-8

  • Getting host, port from the tnsnames.ora with the service name

    Hi.
    I think that I asked a similar question yesterday. I want to ask if there is a way to get host and port from the tnsnames.org with a given service name. Somebody answered it for getting SID in the sqlplus. so I tried it in a similar way, but it didn't work.
    I have a service name, but I don't know how to get host and port. I know that I can parse the tnsnames.ora file to get it, but if possible, I want to use the more official and safe way.
    I'd appreciated if somebody knows it.

    caesarkim wrote:
    Hi.
    I think that I asked a similar question yesterday. I want to ask if there is a way to get host and port from the tnsnames.org with a given service name. Somebody answered it for getting SID in the sqlplus. so I tried it in a similar way, but it didn't work.
    I have a service name, but I don't know how to get host and port. I know that I can parse the tnsnames.ora file to get it, but if possible, I want to use the more official and safe way.
    I'd appreciated if somebody knows it.Oracle RDBMS does not require SQL*Net to operate.
    Oracle RDBMS does NOT now or care about content of any tnsnames.ora file.
    Realize that each (remote) user can have their own personalized copy of tnsnames.ora
    The content of tnsnames not NOT have to reflect any reality.
    I could post the content of my tnsnames.ora & it would be useless to everyone reading.

  • I just purchased Duet 2 and am using it with Garageband 11. I am getting iTunes playbacks through the headphone monitors with Duet 2 but can get no guitar or vocals recorded.  I get no volume

    I just purchased Apogee Duet 2 and am using it with Garageband 11. I am getting iTunes playbacks through the headphone monitors as per quick startup directions. When I open Garageband I get the same identical stack of guitar and on pedal displayed.  I get no sound from the guitar.   I believe I have the set up exactly as per diagram and cannot figure things out.  I am relatively green at this - my best intentioned purchase now feels like a nightmare!!  Help!!

    Yes, you can upgrade to Snow Leopard:
    Requirements for OS X 10.6 'Snow Leopard'
    http://support.apple.com/kb/SP575
    The OS 10.6 Snow Leopard install DVD is available for $19.99 from the Apple Store:
    http://store.apple.com/us/product/MC573/mac-os-x-106-snow-leopard
    and in the UK:
    http://store.apple.com/uk/product/MC573/mac-os-x-106-snow-leopard
    but nobody knows for how long it will be available.
    When you have installed it, run Software Update to download and install the latest updates for Snow Leopard to bring it up to 10.6.8, or download the combo update from here:
    http://support.apple.com/kb/DL1399
    Check via Software Update whether further updates are required.

  • How to get a file in the same dir with the jar-executable

    Hi,
    I need to read/write a file that exists in the same directory with the jar-executable. How can i do that? I think that when i specify no path for the file, the file has to be in current path. (Is that right?)
    Note: I do not know in which directory the jar and the file are.
    Thanx in advance

    Hi,
    I need to read/write a file that exists in the same
    directory with the jar-executable. How can i do that?
    I think that when i specify no path for the file, the
    file has to be in current path. (Is that right?)
    Note: I do not know in which directory the jar and
    the file are.
    Thanx in advance
    When you specify no path for the file, the file has to be in the directory where the virtual machine was started. ( the directory the java command was invoked in .)
    If you can't control the directory in which the vm is started, but you know the name of the .jar file you can do the following. This trick takes advantage of the fact that if you are using classes in a jar file, the name of the jar file must be in your classpath.
    public static String getPathOfJar( String nameOfJar )
    throws Exception
    StringTokenizer st = new StringTokenizer(
    System.getProperty( "java.class.path" ) ,
              System.getProperty( "path.separator" ) );
    String jarfile = "";
    while ( st.hasMoreTokens() )     
    String token = st.nextToken();
    if ( token.indexOf( nameOfJar ) > -1 )
    jarfile = token;
    break;
    if ( jarfile.equals("") ) throw new Exception( "Jar not found in classpath" );
    String path = jarfile.substring( 0 , jarfile.indexOf( nameOfJar ) );
    return path;
    //To open a file in the same directory as the sun archive tools.jar
    File f = new File( getPathofJar( "tools.jar" ) + "someFile.txt" );

  • All plugins uptodate but on upload file get "USING one of the supported browser with latest Adobe Flash is required to experience enhanced file upload features

    I am freelancer. When I tried to upload files on elance it give following error and disable the upload button:using one of the supported browser with latest Adobe flash is required to experience enhanced file upload features.
    All plugins are up to date. Flash version 11.7 installed.

    I assume Firefox 19 worked fine on the site?
    Some sites may be mistakenly identifying Firefox 20 as Firefox 2, which is a very old version they probably no longer support. As a test, you could "lie" to the site about your Firefox version and see whether that little deception works.
    This take a minute to set up. Here's how:
    (1) Select and copy the following preference name to the clipboard:
    general.useragent.override.elance''.''com
    (2) In a new tab or window, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (3) In the filter box, type '''override''' and pause while the list is filtered
    (4) Make sure '''general.useragent.site_specific_overrides''' is set to its default value of true (or right-click and choose Reset if it is not).
    (5) Right-click anywhere in the preference list area and choose
    New > String
    then paste the preference name you copied. Click OK and enter TEMP or asdf or any text as a temporary placeholder. You should see the preference added in bold. Leave about:config open and switch back to this tab.
    (6) Select and copy the following useragent string to the clipboard ''(it's all one line)'':
    Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0
    (That's Firefox 19 on Windows 7 32-bit)
    (7) In about:config, double-click '''general.useragent.override.elance''.''com''' and paste to replace the temporary text with the new useragent string. Click OK, you're done here.
    Now try reloading a page where you need to upload (use Ctrl+Shift+r) and test that function again. Any change?

  • I want to get windows vista on the macbook pro with retina display but my first question is this that how do i install it without using a DVD OR CD disk drive, and my second question while installing windows vista do i have to tick mark the install win 7

    hello i have a few problems and i hope somebody has a solution my first problem is that how can i install windows vista without using a disk drive and my second problem is that should i tick mark the option which says Install windows 7 while using boot camp please reply, Thanks,

    When running Windows in a virtual environment Windows and OSx share your computer's resources such as RAM. Therefore your games can not use all your computer's resources when running.
    If you install Windows natively then Windows and your games can and do use all your computer's resource such as RAM.
    But as already said, older operating systems are not supported and will not run natively using Boot Camp Assistant. You must use Windows 7 if installing natively in Lion or Moubtain Lion.

  • I keep getting a message reading "The server responded with an error...Make sure the URL is correct. Error 404" How do I correct this issue?

    The URL https://calendar.google.com/calendar/dav/[email protected]/user///calendar.google.com/calendar/dav/[email protected]/user/ encountered HTTP error 404. Make sure the URL is correct. How do I correct this issue so that I no longer see this message? Your help will be greatly appreciated.

    I simply un checked calendar in my account settings and closed ical.
    I checked it again, and opened ical.
    Thanks for the tip Linc Davis! but it works without deleting the google account completely. this was pretty straighforward and fast.

Maybe you are looking for