Can i use partition by for the following

hi, i wanted to find out if i can use partition by or rank to the get the needed results below. If yes can anyone help me out with it.
if there is an other way to get the results also please let me know.
i'm using Oracle version 10.2.0.4.0
create table script:
CREATE TABLE DMM.QUES
  CASENAME        VARCHAR2(100 BYTE),
  CASENUMBER      VARCHAR2(20 BYTE),
  COVERAGE        VARCHAR2(10 BYTE),
  DIVISIONNUMBER  VARCHAR2(6 BYTE),
  CLASSNUMBER     number,
  TIER            VARCHAR2(2 BYTE),
  MONTHLYRATE     NUMBER
  )Insert statement scripts:
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','health', '456J','987',null,.25)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','health', '456J','123',null,.25)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','health', '456J','453',null,.25)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','453','ee',.29)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','453','es',.23)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','453','ec',.44)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','453','fa',.33)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','123','ee',.45)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','123','es',.45)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','123','ec',.46)
insert into QUES (CASENAME,CASENUMBER,  COVERAGE,  DIVISIONNUMBER,  CLASSNUMBER,  TIER,MONTHLYRATE)
values ('ABC','123J','dental', '456J','123','fa',.49)select * from ques:
ABC     123J     health     456J     987          0.25
ABC     123J     health     456J     453          0.25
ABC     123J     health     456J     123          0.25
ABC     123J     dental     456J     453     ee     0.29
ABC     123J     dental     456J     453     es     0.23
ABC     123J     dental     456J     453     ec     0.44
ABC     123J     dental     456J     453     fa     0.33
ABC     123J     dental     456J     123     ee     0.45
ABC     123J     dental     456J     123     es     0.45
ABC     123J     dental     456J     123     ec     0.46
ABC     123J     dental     456J     123     fa     0.49i would like to get the following output
ABC     123J     health     456J     123          0.25
ABC     123J     dental     456J     123     ee     0.45
ABC     123J     dental     456J     123     es     0.45
ABC     123J     dental     456J     123     ec     0.46
ABC     123J     dental     456J     123     fa     0.49i would like the code to take the minimum of classnumber for each divisonnumber/coverage combination and give me all the records for that classnumber.
Thanks in advance.

Hi,
That's an example of a Top-N Query , and yes, analytic functions are a good way to do it:
WITH     got_r_num     AS
     SELECT     ques.*
     ,     RANK () OVER ( PARTITION BY  coverage
                           ,          divisionnumber
                      ORDER BY          classnumber
                    ) AS r_num
     FROM    ques
SELECT  casename, casenumber, coverage, divisionnumber, classnumber, tier, monthlyrate
FROM     got_r_num
WHERE     r_num     = 1
;Thanks for posting the CREATE TABLE and INSERT statements, that's very helpful!
"PARTITION BY" is a clause often used with analytic functions. "PARTTIION" also means at least two other things in Oracle, so people will understand you better if you say "analytic functions", rather than "partition by".
For more about the RANK function, see this thread:
Re: A "double grouping" SQL query

Similar Messages

  • Can I use a substitute for the Sample Clock?

    I have three different analog inputs coming from one device (PCI-6221).  Two inputs are running at the same sample rate while the third needs a faster sample rate and a trigger.  I have these seperated as two seperate tasks but my problem is they both use the sample clock.  Can I use a substitute for the sample clock on the third channel?
    I am running LabVIEW 8.2 on Windows XP.
    Thanks in advance for your help.
    Ron Deavers, CLD

    Hi programmindragon,
    I understand you are trying to
    configure your PCI-6221 to sample on multiple channels, while having
    different rates and triggers for the channels. Unfortunately, you can
    only configure one analog input task to run at once and all the channels in
    the task must share the same configurations, including the sample clock
    and trigger. This is due to the fact that all the channels are
    multiplexed to a single amplifier and ADC on the device. Thus, you will
    not be able to configure the two inputs at one rate and use a different
    clock rate and trigger for the third input. Is it possible to sample at the
    maximum rate on all channels and decimate the data that you don't need on the certain
    channels, as well as share the same type of triggering? Hopefully you will be able to run your application with the same configuration across multiple channels, otherwise you may need multiple DAQ devices. Please let me know if you have any further questions related to this issue.
    Regards,
    Daniel S.
    National Instruments

  • I can't use my fingerprint for the App Store?

    I tried re setting it again but couldn't.
    I also read that i have to change the "Restrictions" to 15 minutes for the password, but i don't have that option available.
    What can I do?

    It isn't clear from your question whether you weren't able to enable Touch ID for the store or if it is not recognizing your fingerprint when you use it. The following link has a section related to Touch ID for the store that may help: http://support.apple.com/kb/HT5883

  • I want to install windows7 on my 27in iMAC. I have an OEM version of Win7 which is win pro 7, 64 bit english.  I will use boot camp to partion the hard drive for a win7 install.  Can I use this version for the installation ??

    My iMAC is a 2011 3.4 GHz intel i7 based with a 27in display.  A year ago, I bought a Microsoft win pro 7 64-bit english OEM OS to install over a newly assembled AMD PC.  I never installed it.  Now, I want to put it on my iMAC using either Apple Bootcamp or Parallels.  The win 7 OEM package has a lot of verbage about using an OEM preinstallation kit (OPK) and that it must be preinstalled on the hard drive.  Is it OK to install this win7 version following the Bootcamp instructions.? 
                                          K6JPJ

    Please post in the Boot Camp (not Bootcamp) forum I'm sure someone there can answer your quesiton if no one here is able to.

  • Can I use different colours for the different user accounts in my iCal?

    I have my own iCal and one for my boss. I need our appointments to show up in different colours so that I can tell at a glance which are mine and which are his. Currently our appointments show up on the same calendar, on top of each other, and both are coloured red.
    Can I change the colour of one of us?

    Thanks. If there are other people invited to the appointment it comes up with this
    So I don't want to 'move' it or cancel the original appointment. is there another way I can, for example, have my boss's appointments all come up green and mine all come up blue......

  • Variable selection issue can we use variable exit for the below problem

    Hi experts,
    i have query in which i have an infoobject which is a characterstic i have even set the sort property for that infoobject but when the variable screen comes up and when we go into the selection screen all the help values are not sorted in the way i have set them. for example
    ihave project managers like below
    A
    B
    C
    D
    E
    F
    G
    H
    instead of displaying in order above its displyaing in
    H
    A
    G
    C
    B
    D
    F
    How to set it right.
    thanks and regards
    Message was edited by:
            Neel Kamal

    Hi
    actually i have done the same thing its getting displayed in the bex analyzer but not in the protal.
    thanks and regards
    Message was edited by:
            Neel Kamal

  • Can some one help me for the following issues ......

    while creating the bill in vf01 am getting as the status as open.(ie being processed )in fbl5n Dn is not reflecting

    manjunath2684 wrote:
    begin
    SYS.DBMS_LOGMNR_D.BUILD(
    options => sys.dbms_logmnr_d.store_in_redo_logs);
    end;
    It would be great if some one can explain me what oracle does internally when we run the above procedure. I understand that i writes the dictionary to the redo logs. I am trying to understand:
    1) Where does the oracle read from(Which of the system tables)?
    2) What queries does it internally run to write the dictionary to redo logs.
    Regards,
    Manjunathconsider enabling SQL_TRACE when you invoke this procedure to capture SQL issued

  • I can't use my AppleID for the update of my apps.

    I'm stuck with a friend's ID. I can't even update apps that I've purchased with mine.

    If you need to sign into your device with your Apple ID go to
    iOS 5.1.1: Settings > Store > Select your friends Apple ID and Sign Out, then sign in with yours.
    iOS 6: Settings > iTunes and App Stores > Apple ID > Sign Out
    To eliminate this issue, you should delete any apps off your phone that were not purchased with your Apple ID. Although it's possible to have apps from two different Apple ID's on one device, it's complicated and can get confusing.

  • Can you give me answer for the following??

    Hi here are the links
    http://swforum.sun.com/jive/thread.jspa?threadID=54380&tstart=0
    http://swforum.sun.com/jive/thread.jspa?threadID=54379&tstart=0
    http://swforum.sun.com/jive/thread.jspa?threadID=54378&tstart=0
    http://swforum.sun.com/jive/thread.jspa?threadID=54347&tstart=0
    Thanks
    Sudhakar

    4. export/import, Migration AssistantYou have also the manual upgrade and even data copying according to the Upgrade Guide
    5. network failure, instance shutdown, server failure, >incorrect tns entry, if create session is not granted.You have also:
    - listener down
    - account locked according to password policy
    - the famous ORA-00257,
    - audit trail full
    - maybe also some errors in LOGON triggers
    - etc...

  • HT4718 No 1.    I can not activate Filevault : FileVault can't be turned on for the disk "Macintosh HD". Some disk formats don't support the recovery partition required by encryption. To use encryption, reinstall this version of Mac OS X on a reformatted

    I have TWO PROBLEMS
    No 1.  I can not activate FileVault. It displyas as follows :
    FileVault can’t be turned on for the disk “Macintosh HD”.
    Some disk formats don’t support the recovery partition required by encryption. To use encryption, reinstall this version of Mac OS X on a reformatted disk.
    No 2. I can not activate Find My Mac service. It displays as follows :
    Find My Mac requires a recovery partition
    Some configurations, such as software or hardware RAID, do not support a recovery partition and can't be used with find my mac

    Restart holding down the option/alt key and see if you have a Recovery Volume.
    Recovery Partition – Recreate Without Reinstalling
    Recovery Partition – Recreate Without Reinstalling (Requires Installer)
    Recovery Drive – Restore Missing
    Recovery Disk Assistant

  • When I try to sync my ipad using itunes I get the following message. This iPad cannot be synced. You do not have enough access privileges for this operation. Any ideas how this can be resolved?

    When I try to sync my ipad using itunes I get the following message. This iPad cannot be synced. You do not have enough access privileges for this operation. Any ideas how this can be resolved?

    See if the user tip helps: https://discussions.apple.com/docs/DOC-6562

  • Can my charger, which originally shipped with my iPod A1040 be used with any of the following models without damaging the battery?

    I know this is a complicated question, but any detailed explanation as to why or how I appreciate it as I have tested and it does actually charge the 1136, 1051 and 1236, but I have been reluctant to try it on the A1288.
    Question:
    Can my charger, which originally shipped for the iPod A1040 be used with any of the following without shortening the battery life or damaging it?
    iPod A1136 (tested, does charge)
    iPod A1051 (tested, does charge)
    iPod A1236 (tested, does charge)
    iPod A1288
    Thanks,
    Josh

    Yes, you can use the iPod Mini charger with the new 5th Gen iPod.

  • HT204053 Dear Support Team, every time i tried to logon Icloud its gives me wrong user name or password and at the end it show me error " This Apple ID is valid but is not an ICloud Account" then how can i use one account for same Apple ID and ICloud???

    Dear Support Team,
    Every time i tried to logon Icloud its gives me wrong user name or password and at the end it show me error " This Apple ID is valid but is not an ICloud Account" then how can i use one account for same Apple ID and ICloud?
    Thanks

    It is not possible to create a new iCloud account using a Windows machine. You must create the account using a Mac (10.7.5 or more) or an IOS device (iPhone etc). Once that is done you can sign into and use the account on your Windows machine.

  • I have two iphone one is iphone 5 and othere is iphone 4 . can i use same id for both ? And do i have to purchase the application again for iphone 4 which i have buyed for iphone 5.??

    i have two iphone one is iphone 5 and othere is iphone 4 . can i use same id for both ? And do i have to purchase the application again for iphone 4 which i have buyed for iphone 5.??

    You can use the same Apple ID for both phones, you would then be able to use the purchased Apps/Content on both phones without having to pay again.

  • Can you use one PC for 2 different Ipods, with out erasing the others music from Itunes?

    Can you use one PC for different Ipod touch's , with out erasing the other persons Itunes music?

    Yes.  See:
    How to use multiple iPods, iPads, or iPhones with one computer

Maybe you are looking for

  • Suddenly i can no longer face time from My Mac Air

    My Macbook Air is no longer able to Facetime. it has always been available until recently. i can make a call but it fails repeatedly. any ideas? kind regards

  • What Is Better?

    Two quick questions... 1. Are scene's the only way to make pages in the flash IOS development? 2. whats better touch events or mouse events? thank you for looking and possible responding 

  • How to view Swing sources in Eclipse

    HI all, I work with Eclipse and I want to through Swing code to analyse what is processed. I know it is possible to view Swing source, but I can find the Swing sources in the java jdk delivery. How can I do that? Thanks. Herve.

  • Can Airdrop move Contacts from iMac to MacBook Air?

    Can Airdrop move Contacts from iMac to MacBook Air?

  • Ibase Massive upload with CRMXIF_IBASE_SAVE_M

    Hi Gurus, I am using LSMW to do a massive upload of ibase in solution manager. I used the idoc. Message type: CRMXIF_IBASE_SAVE_M and Basic Type: CRMXIF_IBASE_SAVE01. Right now is working, but I would like to know your opinion, is that okey that I us