need help for this query

Hi gurus

need help with this query,

I want to display the records in the table emp
SQL> Select Deptno,sal,sal/SUMSAL Percent,rn
  2  From  ( Select emp.*,Sum(Sal) Over() "SUMSAL",Row_number() Over(Order by sal Desc) rn
  3   From emp
  4        )
  5  /

      EMPNO     DEPTNO        SAL    PERCENT         RN
--------- ---------- ---------- ---------- ----------
     7839         10       5000 .172265289          1
     7902         20       3000 .103359173          2
     7788         20       3000 .103359173          3
     7566         20       2975 .102497847          4
     7698         30       2850 .098191214          5
     7782         10       2450 .084409991          6
     7499         30       1600 .055124892          7
     7844         30       1500 .051679587          8
     7934         10       1300 .044788975          9
     7521         30       1250 .043066322         10
     7654         30       1250 .043066322         11
     7876         20       1100 .037898363         12
     7900         30        950 .032730405         13
     7369         20        800 .027562446         14

14 rows selected.
               
 
I want just the records
      EMPNO     DEPTNO        SAL    PERCENT         RN
---------- ---------- ---------- ---------- ----------
      7839         10       5000 .172265289          1
      7902         20       3000 .103359173          2
      7788         20       3000 .103359173          3
      7566         20       2975 .102497847          4
      7698         30       2850 .098191214          5
with sum (Percent) of remaing records.....
    Others                          .420327304  
Thank you

Published by: SeenuGuddu on February 27, 2011 03:39
with a as
(
Select
Empno, Deptno ,sal, sal/SUMSAL Percent,
case when rn<=5 then rn else null end rnm
From  (Select emp.*, Sum(Sal) Over() "SUMSAL",
Row_number() Over(Order by sal Desc) rn
From emp)
)
select
case when max(rnm) is not null then to_char(max(empno)) else 'Others:' end empno,
case when max(rnm) is not null then max(deptno) else null end deptno,
case when max(rnm) is not null then max(sal) else null end sal,
to_char(sum(percent), '90.99') percent,
max(rnm) rn
from a
group by rnm order by rnm
EMPNO                                    DEPTNO                 SAL                    PERCENT RN
---------------------------------------- ---------------------- ---------------------- ------- ----------------------
7839                                     10                     5000                     0.17  1
7902                                     20                     3000                     0.10  2
7788                                     20                     3000                     0.10  3
7566                                     20                     2975                     0.10  4
7698                                     30                     2850                     0.10  5
Others:                                                                                  0.42                         

6 rows selected

Tags: Database

Similar Questions

  • Windows Vista is installed on my recovery partition need help for this relocation.

    I have an acer extensa 5620, the labtob supplied with Windows Vista already installed. I ended up having to have my computer repaired because it became somehow infected by viruses a friend who I thought was well knowledged in computers, cleaned the virus or so I thought, and replaces Windows Vista with Windows XP I was not asking or giving permission for that to happen. Now, I came to know that Windows XP is not genuine a software which makes sense because I kept getting virus despite the fact that I have several systems antivirus on my computer and to make things worse, I'm sure I have a browser hijack. I tried to find a way, he made the switch to return to Vista because I liked it, but another friend told me I should stored it on my recovery partition. I don't know that much about computers if anyone can help me to find it and tell me step by step to correctly and safely to reinstall Windows Vista because I'm also fairly certain that bad software is whats allowing these viruses. Help, please!

    http://support.Acer.com/

    Contact Acer for the EXACT way to do.

    There is no Vista free download legal available.

    Contact your computer manufacturer and ask them to send a recovery disk/s Vista set.

    Normally, they do this for a cost of $ small.

    In addition, ask them if you have a recovery Partition on your computer/laptop to restore it to factory settings.

    See if a manual provided with the computer or go to the manufacturer's website, email or you can call for information on how to make a recovery.

    Normally, you have to press F10 or F11, Acer Alt + F10 at startup to start the recovery process...

    Another way I've seen on some models is press F8 and go to a list of startup options, and launch a recovery of standards of plant with it, by selecting the computer repair option

    See you soon.

    Mick Murphy - Microsoft partner

  • need help for this trigger

    create or replace trigger aifer_transfer

    After Insert on transfer

    for each new row

    Start

    UPDATE account SET balance = balance -: new .amount

    WHERE acc_id = from_acc_id;

    UPDATE account SET balance = balance +:new.amount

    WHERE acc_id = to_acc_id;

    end if;

    end;

    create or replace trigger bifer_transfer

    before inserting the transfer

    for each new row

    Start

    If get_balance(:new.from_acc_id) <: new.amount

    then

    raise_application_error (-20001, "not enough money in the account. '");

    end if;

    end;

    create or replace function get_balance (p_acc_id number)

    Return number

    as

    v_balance account.balance%type;

    Start

    Select balance

    in v_balance

    account

    where acc_id = p_acc_id; Return v_balance;

    end;

    Select get_balance (123) double



    ..................................................

    I get this error during the execution of the trigger

    ..................................................



    Error report:

    ORA-01912: ROW keyword expected

    01912 00000 - "keyword LINE WAITED.

    * Cause: Missing keyword

    * Action: provide the missing key

    You need to compile under the correct code.

    create or replace trigger aifer_transfer

    After Insert on transfer

    for each line

    Start

    UPDATE account SET balance = balance -: new .amount

    WHERE acc_id =: new.from_acc_id;

    UPDATE account SET balance = balance +:new.amount

    WHERE acc_id =: new.to_acc_id;

    -end if;

    end;

    create or replace trigger bifer_transfer

    before inserting the transfer

    for each line

    Start

    If get_balance(:new.from_acc_id)<>

    then

    raise_application_error (-20001, "not enough money in the account. '");

    end if;

    end;

  • I need help for this message that I get when I try to download or use my facebook games. It is said. (Is not a valid win32 application) I would appreciate help

    PLEASE, I BEG YOU! If anyone has an idea on how to solve this problem, I would appreciate... I'm really frustraded with her. I can't play games or download anything. Thank you

    Sounds like a problem on Facebook: http://www.facebook.com/help

    Kind regards...

  • Impossible to download Skype, IMO, and Tango. Need help for this.

    I'm on samsung SGH-i677 and can't download Skype, IMO, tango. Can you help me to update?

    First uninstall Skype:

    http://Windows.Microsoft.com/en-us/Windows/uninstall-change-program

    Delete the C:\Program files Skype

    (If you are running Windows 7 64 bit look in the folder C:\Program Files (x 86)

    Download the latest version of Skype:

    http://www.Skype.com/en/download-Skype/Skype-for-Windows/

    Temporarily disable your Antivirus:

    http://Windows.Microsoft.com/en-us/Windows/disable-antivirus-software

    Perform a clean boot:

    http://support.Microsoft.com/kb/929135

    Try to reinstall.

    Resources:

    https://support.Skype.com/en/FAQ/FA164/i-have-a-problem-downloading-Skype

  • I have 350 MB of photos on my photo library to iCloud. And used to synchronize the photos to my iPhone, I need help for this thank you

    I have an iPhone 4 32 gb

    You are connected to iCloud in settings/iCloud and Photos of synchronization are enabled?

    Try the settings/iCloud and remove the synchronization. Wait a few minutes and then resynchronize.

    Have you tried the signature to iCloud and then reconnect?

  • Dialog box that says ' Creative Cloud Installer wants to make changes. Type your password for this purpose"- I type my password for Adobe ID (creative cloud), but it will not accept it. who should I go for help with this query?

    Dialog box that says ' Creative Cloud Installer wants to make changes. Type your password for this purpose"- I type my password for Adobe ID (creative cloud), but it will not accept it. who should I go for help with this query?

    It does not ask the cloud your computer admin password password!

  • Is there a default value for the color management in PSE10? Beautiful photos from iPhoto, but blur with elements. I need help with this before as I consider that the upgrade to PSE13 and beyond.

    Is there a default value for the color management in PSE10? Beautiful photos from iPhoto, but blur with elements. I need help with this before as I consider that the upgrade to PSE13 and beyond.

    Printing which forms an angle seems ok, but one that is horizontally seems faded, incomplete.

    I was wondering if I saved a layer somewhere and set it as a default value.

    If you group the layers, you will be left with a single layer, thus spreading your concern.

    Suggest that you do the following:

    1. Make sure you have the latest drivers for your printers
    2. Reset the default preferences.

    Hold the Alt, Ctrl + Shift keys when you click the icon to open the items. When asked if you want to delete the settings file, say Yes.

    Items nearby and let regenerate the file.

  • Need help for optical safety circuit.

    I buy these parts and prototype with real components, but since I multisim, I thought it would be nice to create the circuit and maybe work through issues I can practically.

    I need a circuit that takes 120 VCA, generates 5 VDC and 1.5Vdc power of optical transmitter and receiver.  I actually use a data port because he has great range and is pretty cheap.  Rather than send the binary code well I just send a light stead that is broken or not broken through doors and windows in my house.  Then the receiver sees this as an entry and order a relay.

    I tried several voltage regulators that come with multisim, but I get an error of execution of my circuit.  Really I can't the 120 VAC to power levels necessary for the functioning of the optics.

    Otherwise I might want to run on a system 120Vdc with battery backup, so throw a 120Vdc up to 20 v DC switching power supply - but I have not found a SMP in the library which takes 120 as input and as output 20.

    Basic plan: 120VAC source-> transform to 24Vac-> Full bridge rectifier to ~ 20 v DC-> voltage capacitor filter on the input of two voltage regulators (1 to 5 VDC, 1 to 1.5Vdc) - then circuit since the two power supply of the transmitter and the receiver.

    I just need help for 5V and 1.5V, from there, I know that the real world circuit will work component tests already carried out.  Thanks for reading.

    I didn't Multism so I can't advise you on the compatible models. I ran the model on semiconductors with slight modifications of format on my SPICE simulator based on Berkeley Spice 3f5. I had to change the format of model resistance semiconductors appeal but has not changed any values.

    The output of your power supply circuit 3 (with 5 V, not the 1.5 V regulator regulator) was 4.99995 V.

    There are a few messages about changing templates published for compatibility Multisim woth. You can search those to see if there are any suggestions on what you'll need to fix in the model.

    Lynn

  • I need help for the upgrade of my current system.

    I need help for the upgrade of my current system.

    I have SBS 2008 with (Exch 2007, SQL 2005, Sharepoint, backupexec 2010 for sbs) licenses.

    I want to make the larger environment using the following:

    (1) apply Virtualization

    (2) apply to the failover process (clustering)

    "(3) the environment must support adding server terminal server, ERP server, exchange server, domain controller, backup manager.

    Storage 4) that supports Raid (1 and 5)

    UTM excellent 6) that supports (SSL VPN, VPN Global)

    suitable backup solution 7)

    (8) good antivirus for clients

    my questions:

    (1) can you provide me with a good design for this environment

    (2) should I choose what operating system:

    Microsoft datacenter or company

    I know datacenter provide us the unlimited VM but needs per processor license

    so if I have two Grouped servers I want to buy 4 licenses

    and just 4 VMs per company license... to say that we have two servers and maintain 8 vms so wat happened if 1 goes down... How can I migrate the 4 virtual machines on the server failed to another server group... ? should I buy enterprise license?

    (3) if I get the SAN storage for data... How can I save this storage... should I get another SAN?

    (4) how can I upgrade SBS stad single server (windows standrad) without losing the licenses as Exch 2007, SQL 2005, sharepoint.is it a must to buy an edition full std server or there is a way to upgrade (license wise, I mean)?

    (5) what about win2k8 license for VM:

    lets say we have physical that has windows license so that enough to have windows for VM or should I buy windows for VM licenses?

    (6) can I use backExec license for SBS with windows 2008 standard

    (7) who better to virtualization AMD or INTEL

    (8) hyper V or VMware?

    (9) what of Microsoft data protection Manager... is this good?

    (10) what virtual machine manager? What are the benefites keys

    Thanks in advance

    Hello AnasAI,

    You can find the Server forums on TechNet support, please create a new post at the following link:

    http://social.technet.Microsoft.com/forums/en/category/WindowsServer/

  • [Error number: 0x8024400A] Need help with this error... I reinstalled XP SP1 and I can't get an auto update that's simple to install, just get this error every time

    [Error number: 0x8024400A] Need help with this error... I reinstalled XP SP1 and I can't get an automatic update that's simple to install, just get this error at each time HHHHEEEELLLPPPPP! Thank you

    I had the same problem.  But finally found a solution.  If your listing is similar to mine, then keep.  XP Media Center Edition 2005 (sp2).  AMD Athlon 64 x 2 Dual-Core, HP a1630n desktop computer.

    Go to the HP website, search for sp37394-XP sp3 Upgrade utility Microsoft for systems equipped with AMD processors.

    I had the same 0 x 80240036, 0x8024400a error, but realize my problem was really get manually downloaded sp3 and installed without continue loop crashing and not error messages.

  • Need help with a query result

    Oracle Version: 11.2.0.2.0

    I need assistance with the output of the query. Here is the table.

    With Tbl_Nm as

    (

    Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select * from tbl_nm

    I need the output below.

    PQR2 UK MC 2600 1 OCTOBER 2012 04:45

    ABC1 US NY 3500 October 1, 2012 06:45

    LMN3 UK BT 2500 November 1, 2012 07:45

    The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.

    I've tried a few and got stuck. Help, please. Not able to get a balance '.

    This question is a bit similar to needing help with a query result

    With Tbl_Nm as

    (

    Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1

    where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)

    So maybe you'd then

    ORDER BY DECODE(flag,'D',9,1) ASC...

    to get the Ds at the end of the list.

    or

    ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...

    HTH

  • I need help for my reader to USB drive on my windows 10 ACER?

    I need help for my reader to USB stick on my chrome windows 10 plug ins acer. Can you help me?

    What Adobe application that you use?

    This is the Adobe Media Encoder forum, and you did not mention anything on this subject. If you can let us know what Adobe application, you need help, we can help you make the right forum.

    Thank you

    Regalo

  • Need help with this gallery of xml!

    I have build a gallery but its very simple... There are pictures of the xml file.

    I have attached all the zip files.

    I just want two things if anyone can help.

    first of all when I press the next button, he's going to the next image, but without effect. It just displays the following image... I want to incorporate the effect of dragging when the image is changed to another.

    and secondly, I want to use the AutoPlay feature.

    Once swf starts images came one by one with a vertical drop of a few seconds.

    Thanks in advance... I really need help with this..!

    For the look of sliding effect using the actionscript class Tween.  Allows you to create motion tweens using the code.  The example below will be tween property _x of the instance named anObject from 0 to 300 in 3 seconds...

    import classes before using

    Import mx.transitions.Tween;
    Import mx.transitions.easing.Regular;

    TW var = new Tween (anObject, "_x", Regular.easeIn, 0, 300, 3, true);

    To implement an enforcement function auto you need to import all the images first, in the order, then you will need to use form any controlled timer, such as setInterval (with clearInterval not to need) in order to have things turn on automatically by some part-time

  • I need help confirming this phone I did not steal F1 * F9R

    I need help confirming this phone I did not steal F1 * F9R

    < personal information under the direction of the host >

    Here nobody.

Maybe you are looking for

  • No book iBooks in itunes

    I used to charge my books that I had in my iPad via iTunes iBooks, but now when I connect my iPad to my Macbook it shows 0 Books in sync in iTunes, but all the books are still in iBooks, I can't move books or another store not bought a PDF file to my

  • Moto G4 display not 'breathing '.

    Hi all Does anyone know if turning on the screen of the motorcycle should display notifications to the discoloration? For me the screen only briefly lights up when I move the phone but he don't "breathe" at all times, so there is no way for me to kno

  • Pavilion x 2 detactable: power off the touch screen

    I want to use my laptop / Tablet drawing and illustrations. I wanted to turn off the touch screen so that I can use it to make drawings with. Any help would be apprecated. Thank you

  • How to merge two partitions in XP

    I have Windows XP Service Pack 3. The space becomes very low on my NTFS Partition that contains Windows XP. There are partition with more than 100 GB of free space I want to access - preferably by merging two partitions or not not to resize the NTFS

  • Recover everything App Crash Log in client device

    Hello world I developed an application of game and because it is a 3D game, using a lot of resources of the device, it will crash / frozen in our device of players (customers), I need to know why. The problem is in the Passport, before releasing pass