How can I return results based on 2 columns?

I have had a problem and it cannot know for life. First of all, here is a series of example data that I use so you can see exactly what I'm asking.

EmplId Effdt Effseq            

10001 1 JANUARY 99 ' 0

10001 1 JULY 11 ' 0

10001 1 JULY 11 ' 1

10001 1 JULY 11 ' 2

10001 1 JULY 12 ' 3

Do I have to do here is get 3 ranks. 3 rows, I need are lines 1, 4 and 5. I need rank 1 because it's a different date. I need line 5 for the same reason: it is another date. The question arises with how I can get the rank 4. The problem is that the lines 2, 3, 4, and all have the same date (effdt) effective, Developer SQL just returned one of these lines. Because these 3 rows all have the same date (effdt) effective the switch becomes the actual sequence number (effseq). When the date (effdt) effective is the same, you enter the maximum number of sequence (effseq) effective and return results of this whole line as the emplid, effdt and effseq. It seems so simple and something that you can use a subquery for, but its not as simple as that. Note, that you can specifically use the emplid = 10001 in any specific form because there are many employee also id, the lines will not be in a specific order so that you can always just grasp the lines 1, 4 and 5. Some employees may have only a single line in the database, and some may have 50 lines. Everything depends only on the combination of employee id (emplid) date (effdt) efficient and effective sequence (effseq) as the tiebreaker. Any help to fix this would be greatly appreciated. Thank you in advance.

WITH t
     AS (SELECT 10001 emplid,
                TO_DATE ('01-JAN-1999', 'dd-mon-yy') effdt,
                0 effseq
           FROM DUAL
         UNION ALL
         SELECT 10001, TO_DATE ('01-JUL-2011', 'dd-mon-yy'), 0 FROM DUAL
         UNION ALL
         SELECT 10001, TO_DATE ('01-JUL-2011', 'dd-mon-yy'), 1 FROM DUAL
         UNION ALL
         SELECT 10001, TO_DATE ('01-JUL-2011', 'dd-mon-yy'), 2 FROM DUAL
         UNION ALL
         SELECT 10001, TO_DATE ('01-JUL-2012', 'dd-mon-yy'), 3 FROM DUAL)
SELECT emplid, effdt, effseq
  FROM (SELECT t.*,
               ROW_NUMBER ()
                  OVER (PARTITION BY emplid, effdt ORDER BY effseq DESC)
                  rn
          FROM t)
 WHERE rn = 1
EMPLID EFFDT EFFSEQ
10001
01/01/1999
0
10001
01/07/2011
2
10001
01/07/2012
3

Tags: Database

Similar Questions

Maybe you are looking for

  • Unlocked IPhone connected to a carrier

    Hi all My friend who went to the U.S.A. recently bought an iPhone 6 s for me. Today, she sent an e-mail me the reception and it says that the device is bought in * full price * connected to the carrier of Sprint. So, it means that it's unlocked? I li

  • View report TestStand in modular VI

    Hi all I am creating a VI (LabVIEW 2011) which is called from TestStand (2010). The purpose of this VI will display the results of the test at the end of a test sequence. The VI must contain a button that the user can press to close and continue. My

  • XP freezes before loading personal settings

    XP STARTS TO LOAD THEN GOES TO BLUE SCREEN, MOUSE ŒUVRES BUT CAN'T DO

  • Keep all programs and files on a CD, so there is nothing on the computer

    Hello In years past, I used to keep all my files and programs on a "floppy". I can do this in Vista, so there is nothing but the OS and the A / virus on the HARD drive, and when I use the computer, I just loaded my CD, and then select the files or th

  • Taskbar Wizard of PayPal payment request

    I am trying to install the PayPal payment assistant task bar.  Everything seems fine, but it does not install on Outlook.  Any help!