identify the most recent candidate

First I'm sorry for the creation of a long term position, just trying to understand.
Please help me make my efficient query.

Example followed with a logic behind the scenes.

create table finalcand (ptsequence number,version number,candidate varchar2(10),date_submitted date,
file_valid varchar(2))
insert into finalcand values(101,1,'VJ',TRUNC(SYSDATE),'Y');
insert into finalcand values(102,1,'RD',TRUNC(SYSDATE),'Y');
insert into finalcand values(103,1,'GD,TRUNC(SYSDATE),'Y');
insert into finalcand values(104,1,'GD',TRUNC(SYSDATE),'N');
insert into finalcand values(105,2,'GD,TRUNC(SYSDATE),'Y');
insert into finalcand values(107,2,'GVR',TRUNC(SYSDATE),'N');
insert into finalcand values(106,1,'GD',TRUNC(SYSDATE+1),'Y');
insert into finalcand values(108,1,'GD',TRUNC(SYSDATE),'Y');
insert into finalcand values(109,2,'GVR',TRUNC(SYSDATE+1),'Y');
o/p required
   PTSEQUENCE    VERSION    PATIENT DATE_SUBMITTED FILE_VALID   RNK
     105     2     GD     7/23/2009           Y             2
     108     1     GD     7/23/2009           Y             3
     103     1     GD     7/23/2009           Y             4
     104     1     GD     7/23/2009           N             4
     107     2     GVR     7/23/2009           N             2
IM using this query that works perfectly, but I'm still trying to see if I can do it effectively.
SELECT z.*
  FROM (SELECT r.*,
               RANK() OVER(
               PARTITION BY r.candidate 
               ORDER BY R.DATE_SUBMITTED DESC,
                        R.VERSION DESC, 
                        R.PTSEQUENCE desc) rnk
          FROM finalcand r
          where file_valid='Y') z
 WHERE RNK >1
union all
SELECT z.*
  FROM (SELECT r.*,
               RANK() OVER(
               PARTITION BY r.candidate  
               ORDER BY R.DATE_SUBMITTED DESC,
                        R.VERSION DESC, 
                        R.PTSEQUENCE desc) rnk
          FROM finalcand r
          ) z
 WHERE RNK >1
 and z.file_valid='N'
Logic behind it all

This is to identify all records that are no more final candidate

-> candidate is identified by the name of the candidate.
-> version and date_submitted is used to identify the most recent entry of this candidate.
-> if same candidate has several entries with the same version and also date_submitted even then use max (ptsequence) to identify the most recent.

Problem here is
-> if we see a candidate with File_valid input = ' don't this means that the earlier version of this candidate should be the most recent.
An other problem is
-> if we see a candidate with File_valid input = ' don't and no not all old records, then the current should be the last.


Thanks for reading this post.

Published by: user5495111 on July 23, 2009 13:37

OK then, this query matches your output (with the exception of the rank column)

select * from (
select r.*
     , row_number() over (partition by r.candidate
                              order by r.file_valid desc
                                  , r.date_submitted desc
                                  , r.version desc
                                  , r.ptsequence desc) rn
  from finalcand r)
  where rn!=1
  order by candidate, rn

PTSEQUENCE  VERSION  CANDIDATE  DATE_SUBMITTED    FILE_VALID RN
----------- -------- ---------- ----------------- ---------- ----
105         2        GD         23-JUL-2009       Y          2
108         1        GD         23-JUL-2009       Y          3
103         1        GD         23-JUL-2009       Y          4
104         1        GD         23-JUL-2009       N          5
107         2        GVR        23-JUL-2009       N          2   

5 rows selected

Tags: Database

Similar Questions

  • OS - 10.11 El Capitan does not support Ms word or excel.  What is the most recent upgrading OS 10 which will support these applications?

    I have the following MAC PRO:

    Model name: MacBook Pro

    Model identifier: MacBookPro8, 1

    Processor name: Intel Core i5

    Memory: 4 GB

    Boot ROM version: MBP81.0047.B27

    Version of the SCM (System): 1.68f99

    Serial number (System): C02G4Z0TDH2G

    Material UUID: D58D2195-F16E-5570-AB72-A71613DC1C29

    If I download OS 10.11.3, how can I open my word/excel files if MS word excel cannot be used with it?

    You can use Microsoft Office 2008, 2011, and 2016, Pages and numbers, LibreOffice or similar software (not including previous versions of Microsoft Office.) The most recent operating system that supports Microsoft Office 2004 is 10.6.8.

    (139184)

  • After WSUS downloaded and installed the most recent Windows XP and 7 updates, we encountered the following error: page of the Intranet Web displayed in Internet Explorer (8 or 9) is on SERVER_A

    After that WSUS installed and downloaded the most recent Windows XP and 7 updates, we encountered the following error:

    The Web page of the Intranet being viewed in Internet Explorer (8 or 9) is on SERVER_A
    and the page contains a link to a file on a network share on the Serveur_B, making the href path something like
    'http://SERVER_B/myShare/myDocument.doc '.
    ... then it does NOT work.

    If the Intranet Web page being read in IE (8 or 9) SERVER_A on
    and the page contains a link to a file on SERVER_A, making the href path something like
    'http://IP..ADDRESS/myDocument.doc '.
    ... then it does not work.

    Before these updates, the system worked flawlessly.  We try to identify the update that caused this problem, but 28 of them fell on a Tuesday.  (22/11/2011).   These questions are the same with IE8 or IE9 and WindowsXP and Windows7.

    Has anyone seen this problem?

    Thanks, Jim

    It is a specific consumer support forum.

    You will find support for WSUS in this forum: http://social.technet.microsoft.com/Forums/en-US/winserverwsus/threads

    You will find support for Windows XP in an enterprise in this forum environment: http://social.technet.microsoft.com/Forums/en/itproxpsp/threads

  • Failed to sync files - missing the most recent version of the file

    I have two files in the cloud: my Lightroom Catalog and previews file support and work between my desktop and laptop. I have not opened the file LR catalog of the workstation from the 3/10, but have used in on my laptop at all times. After you install the updates today, he asked me to sign the creative cloud, which I did. When I look at my creative cloud file, my two files had been replaced by the OLD version of the file on the desktop, changed the 3/10. The most recent version, current disappeared that I worked for a month. None of the work I did on Lightroom, hours and hours, no longer appears. Please help me find the latest version of my file!

    Also: it does not appear on the files "Archived" on my account. The last archived version was 3/10. If the file I used for the past month, never synced to the cloud, why it has been replaced by an older version of the file?

    With the recent update of the application of Creative Cloud Desktop (1.9.1.474), we have unfortunately introduced a bug that causes the creation of a new Creative Cloud Files folder and re-synchronization of all content. This will happen only the first time that the synchronization application runs after the update. This caused an understandable pain and confusion, for which we really apologize.

    Creative application Cloud Files contains a logic that supports the use of several Adobe ID. This allows to disconnect from an ID and in, but keeps the contents of your separate creative cloud. When you sign out and change identifiers, the app moves the previous creative Cloud Files folder and it's content and he adds with the already signed in ID (User@AdobeID). Then, it creates a main folder and begins to synchronize the content of the identification of new.

    The bug I mentioned earlier occurs, as the app believes an ID selector took place and as such, moves the current record of Creative Cloud Files and attempts to annex the already signed in ID. As no switch actually took place, it manifests as (unknown).  The application then creates a main folder to synchronize the data.

    What you end up with is essentially a creative Cloud Files folder with your new synchronized data and a creative Cloud Files (unknown) folder that contains duplicate data.

    This happens once, after the last update.

    The solution is to simply delete the (unknown) Creative Cloud Files folder.

    I recommend that ensure you that you have no pending change you can do offline and you check the contents of the folder new, main designer Cloud Files contains everything you expect of him.  If this is not the case, check the contents of the creative Cloud files (unknown).

    If there is still an incompatibility with your data, you can check on creative.adobe.com to confirm that your data is there.

    If you have any other problems or questions on this topic please email [email protected]

  • I did the most recent iOS 10 updated, just heard on the news that Yahoo has been hacked.  I changed my Yahoo email but can't find the field to change on my devices.  It is simply not there, what is happening?

    I did the most recent iOS 10 updated, just heard on the news that Yahoo has been hacked.  I changed my password to Yahoo mail but can't find the field to change the password on my devices.  It is simply not there, what is happening?

    For some reason any change automatically if change you it online. Today, I changed my password through my office and I went to change the mail and she had already changed.

    You can try to delete your account your unit off and add it again.

  • Try to add a page to a pages document. It worked until now but just finished page 13 with text and photos and cannot add another page, using macbook pro with El Capitan and the most recent version of the Pages.

    Try to add a page to a pages document. It worked until now but just finished page 13 with text and photos and cannot add another page, using macbook pro with El Capitan and the most recent version of the Pages.

    You have placed your beam to insert at the end of your text on page 13 and then apply Insert menu: Page Break? In the v5.6.2, Pages I just add a new page to a section of four pages to this approach.

  • I have Firefox 38.2.0 and it tells me that it is the most recent version but online there is version 40 + and it won't let me install it.

    My OS is Windows 10. I have Firefox 38.2.0 and it tells me that it is the most recent version. However, I got emails telling me to upgrade to the latest version which seems to be in the 40s. When I go to the https://www.mozilla.org/en-US/firefox/new/ website, it tells me
    "Looks like you are using an older version of Firefox."

    So I click on upgrade and it loads a file "stub". I close in Firefox, go to the folder where the file is located and run it. At the end of the process, he told me that Firefox still works and I have to close it for the new version to load. Then I go to the Task Manager, and he told me that no request to don't run! I went through this process three times without any positive result.

    What to do?

    I'll answer your question, but I suggest not changing your version of Firefox until find us out if having to do any with your plant, discussed here: https://support.mozilla.org/questions/1078897

    At some point, there are two different versions of Firefox:

    • Public release of the standard/large: currently Firefox 40.0.2
    • Extended support release (ESR): currently Firefox 38.2.0

    The version of ESR is intended for companies who need maximum stability for their users. New features usually are not added for at least six months, although security patches are issued approximately every six weeks.

    You want to switch to the standard version? If so, this is how I suggest to do:

    Clean reinstall it

    We use this name, but it isn't about deleting your settings, this is to ensure that the program, files are clean (not incompatible, corrupt or exotic code files). As described below, this process does not disrupt your existing settings. Don't uninstall NOT Firefox, that does not need.

    (A) download a fresh Installer for Firefox 40.0.2 of https://www.mozilla.org/firefox/all/ in an ideal location. (Scroll down your preferred language).

    (B) the release of Firefox (if any).

    (C) to rename the program folder, either:

    (Windows 64-bit folder names)

    C:\Program Files (x86)\Mozilla Firefox
    

    TO

    C:\Program Files (x86)\FxESR
    

    (Windows 32-bit folder names)

    C:\Program Files\Mozilla Firefox
    

    TO

    C:\Program Files\FxESR
    

    (D) run the installer downloaded to (A). It should automatically connect to your existing settings.

    Note: Some plugins can only exist in the old folder. If it is missing something essential, present in these files:

    • \FxESR\Plugins
    • \FxESR\browser\plugins
  • Can you is more middle - click on the buttons back and forward to open the most recent last/next page as a new tab?

    I use Firefox 26, and I remember at some point in the past you could middle - click on the buttons back and forward to open the most recent last/next page as a new tab. Now, it does not work. I have not changed anything else on Firefox I know works, so was it gradually as keyword.url or is this something else?

    ... OK, this is weird. I restarted Firefox in safe mode and the reworked for/back Middle-click, so I thought it was one of my modules. Yet once, I opened Firefox in normal mode... and Middle-click works.

    I have no idea.

  • Firefox continues to show that I need high-grade firefox but I have the most recent, how to stop it

    Popup message that I need to high-grade, fire fox, already have the most recent in a (No 26). Have uninstalled and reinstalled and still get the message that I need to up grade, have windows 7.

    Whenever you get a message / popup that software / files must be updated.

    DO NOT USE ONE OF THE LINKS PROVIDED.

    If this can be a legitimate message, could also be a Virus or Malware.
    No matter when you want or need to check updates.
    Go to the website of the real owner of the program in question.
    For example, for Firefox, go to Mozilla.org
    or Firefox in any language.

  • Sometimes, I get a notice from a site that Firefox needs an update. When I go into FIrefox, it says that I use the most recent version. What is happening?

    I wonder if these sites are trying to make me download malware or virus. If I go to the Firefox site and it says that I use the most recent version, I think Mozilla tells me and wonder "why a site told me that I have to update? I hope only that Mozilla and not blindly download something without studying. Am I paranoid?

    No, it's a scam which is the link to the site, mozilla does not use a site to ask you to update, it uses an automatic update.

    You can report it here

  • The most recent episode is to Download Stitcher but NOT iTunes?

    So my last episode does not appear on the iTunes store that my 32 other episodes are fine no problem but the most recent is not. I downloaded it almost a week ago so I know this isn't a thing of timing because they are usually no more than a few hours of posting. Stitcher has also the most recent episode so I'm pretty confident that my feed is working.

    Perhaps you have not allowed enough time for the Bank to update. You have perhaps fallen on an intermittent bug in the store. Perhaps there is a mistake in your stream. If you post the URL of your store page and feed there is no way of knowing.

  • My firefox does not work llook like the most recent version. I downloaded it on my aunts comp and in the corner upper lft, there's a firefox orange box but still just mine has firefox symbol.

    I had firefox for over a year and I recently installed on my computer of aunts. When I've done in the upper left corner, there was an orange box that says firefox on it. I have recently installed on my computer and it's always the same, as I had before. (Just the symbol of firefox) How can I get the latest version? It does not say I have the 6.2 or what is the most recent. Thank you in advance for the quick response to my question.

                                        Amy Vitko
    

    The current stable version is Firefox 6. 0.2

    https://support.Mozilla.com/en-us/KB/how-do-i-get-Firefox-button
    Why can't I see it?

    To make Firefox look like other programs in Windows XP, the menu bar is displayed instead of the Firefox button, while under Windows Vista and Windows 7, the button is displayed by default in Firefox.

  • How do you get the most recent backup that always has this app on it?

    My 2 years has removed an application in the course of the past week. He regularly plays with my phone, so I have no idea when he managed to do so. I do iCloud backups every night and have this updated app to make backups as well. Is there a way to check the applications included in backups to restore the most recent backup with this app still on it and I hope that the latest data? The only option I can think of right now is to keep remove and restore my phone until I get to a backup with the application, but this seems incredibly long.

    You can see a breakdown of the contents of the backup of the last backup. If you know that it has been deleted some time in the past week, restore a backup from a week ago. If there was some new data on the phone since then you do not want to lose, then Yes, you would probably try the trial and error method.

  • What is the keyboard shortcut to return to the tab previous (I mean the most recent tab)?

    Normally, I work on Firefox with several tabs open. I want to pass between two tabs open frequently. Is there a shortcut to do? for example. "Alt + Tab" to open the most recent window on the Windows operating system.

    Which probably only works if you turn on the Preview tab control.

    You can set the pref browser.ctrlTab.previews true on the topic: config page.

    To open the topic: config page, type Subject: config in the address bar (address) and press the 'Enter' key, as you type the url of a Web site to open a Web site.

    If you see a warning then you can confirm that you want to access this page.

    • Use the filter at the top bar of the on: page config to more easily spot a preference.
    • Preferences that have changed see the bold (user set).
    • Preferences you can restore the default value or change via the context menu.
  • The most recent update 9.3 works on iPad 2?

    I had to restore iPad 2 2 at the factory after the first update 9.3 settings. The most recent update work?

    He does. However older devices, in particular the ipad 2 have had problems. First to not being not able to activate, not then the fix for which focused on the problems with Safari and links in emails.

    So if you had problems, you're in good company.

Maybe you are looking for

  • Satellite NB550D-109 - recovery partition

    You just bought a NB550D-109.Pretty happy with it, but I have a few questions so.Is there a reason the recovery partition labled data, is half the size of the drive? This partition can be resized to give more storage without compromising the Recovery

  • part number HP 8600 output tray

    My on my 8600 (749n) printer output tray is broken.  What is the spare part number?

  • Product key not accepted when you try to install Windows XP.

    Windows Xp reinstall the product key invalid pop up OK, so here starts my road of woes. First of all, I got a problem with a driver updated on a COMPAQ DeskPro ENS P866. It complements removed all the sounds of this PC. I tried every fix on every tec

  • CD/dvd problems

    I have a dell dimension 3000 desk top and my cd/dvd drive has disappeared.It is a Phillips dvd8701, I tried to use the registry key without success cleaners. When I try to reinstall it is the error message I get. Windows cannot load the driver for th

  • Web browsers freezes / hangs intermittently - Firefox/IE11

    Recently installed Win7 64 bit on a PC with Windows Vista already. Periodically, my browser starts unresponsive. For example. Open Firefox, normal... click a link to a site web, data gets transmitted (little logo goes round and round at the top left)