Group by and save County simplification, try #2

I know what I'm trying to do, don't know how to get there. I provided do it table and inserts as well as the query is not working.
/*table*/
CREATE TABLE claims_step_table (  
table_id       INTEGER PRIMARY KEY, 
record_id      NUMBER,  
step_code      VARCHAR2(20 Byte),
date_completed DATE,
step_date      DATE
)

/*inserts*/
INSERT INTO claims_step_table VALUES (1,  123456,'P96','10-JAN-09','05-JAN-09');
INSERT INTO claims_step_table VALUES (2,  123456,'L61',null,'05-JAN-09');
INSERT INTO claims_step_table VALUES (3,  67,'P96','10-MAR-08','05-MAR-08');
INSERT INTO claims_step_table VALUES (4,  67,'L61',null,'05-MAR-08');
INSERT INTO claims_step_table VALUES (5,  67,'U18',null,'05-MAR-08');
INSERT INTO claims_step_table VALUES (6,  67,'429',null,'05-MAR-08');
INSERT INTO claims_step_table VALUES (7,  9876,'L61',null,'05-FEB-08');
INSERT INTO claims_step_table VALUES (8,  9876,'429',null,'05-FEB-08');
INSERT INTO claims_step_table VALUES (9,  123456,'P96','10-AUG-07','05-JUN-07');
INSERT INTO claims_step_table VALUES (10, 123456,'L61',null,'05-JUN-07');
INSERT INTO claims_step_table VALUES (11, 123456,'U18',null,'05-JUN-07');
INSERT INTO claims_step_table VALUES (12, 123456,'429',null,'05-JUN-07');
INSERT INTO claims_step_table VALUES (13, 67555,'L61',null,'07-NOV-08');
INSERT INTO claims_step_table VALUES (14, 67555,'P96','08-NOV-08','07-NOV-08');
INSERT INTO claims_step_table VALUES (15, 67555,'429','15-NOV-08','07-NOV-08');
COMMIT;

/*query*/
SELECT
    RECORD_ID,
    max(STEP_DATE)
    from(
            select 
            RECORD_ID,
            STEP_DATE,
            case
                when STEP_CODE = 'L61' then DATE_COMPLETED
            end as STEP_L61,
            case
                when STEP_CODE = 'P96' then DATE_COMPLETED
            end as STEP_P96,
            case
                when STEP_CODE = 'U18' then DATE_COMPLETED
            end as STEP_U18,
            case
                when STEP_CODE = '429' then DATE_COMPLETED
            end as STEP_429
        from
        CLAIMS_STEP_TABLE
        where
            STEP_CODE in('L61','P96','U18','429')
    )
where
    STEP_L61 is null
and
    STEP_P96 is not null
and
    STEP_U18 is null
and
    STEP_429 is null

group by RECORD_ID, STEP_DATE
order by RECORD_ID, STEP_DATE DESC
What I need is all RECORD_ID and STEP_DATE where
• STEP_CODE L61, U18 and 429 the null value AND STEP_CODE P96 is over
• Only the more recent recordings based on the STEP_DATE (so the step_date max), if of multiple RECORD_ID.


The query should return * 2 * n - tuples
RECORD_ID       MAX(STEP_DATE)
67             03/05/2008
123456             01/05/2009
I am currently getting the following
RECORD_ID       MAX(STEP_DATE)
67             03/05/2008
67555             11/07/2008 <= step 429 not null
123456             01/05/2009
123456              06/05/2007 <= old record need newest
It is a much more simplified than the original query as it has several joins of tables. There are 100 records of k + in the real CLAIMS_STEP_TABLE with more than 1 different k STEP_CODE. (it is a fictitious table for this example). BTW on the real DB, I have only read access.

Thank you for your patience and understanding with a noob, hope this attempt is more clear.

The reason why it is failing because your pivot (inner query) is return few results:

 RECORD_ID STEP_DATE STEP_L61  STEP_P96  STEP_U18  STEP_429
---------- --------- --------- --------- --------- ---------
    123456 05-JAN-09           10-JAN-09
    123456 05-JAN-09
        67 05-MAR-08           10-MAR-08
        67 05-MAR-08
        67 05-MAR-08
        67 05-MAR-08
      9876 05-FEB-08
      9876 05-FEB-08
    123456 05-JUN-07           10-AUG-07
    123456 05-JUN-07
    123456 05-JUN-07
    123456 05-JUN-07
     67555 07-NOV-08
     67555 07-NOV-08           08-NOV-08
     67555 07-NOV-08                               15-NOV-08

So in the case of 67555, there is a situation where all the outer query conditions are met. What you need to do is to remove the extra NULL values as follows:

SELECT  RECORD_ID
,       STEP_DATE
,       MAX(CASE
                WHEN STEP_CODE = 'L61' THEN DATE_COMPLETED
        END) AS STEP_L61,
        MAX(CASE
                WHEN STEP_CODE = 'P96' THEN DATE_COMPLETED
        END) AS STEP_P96,
        MAX(CASE
                WHEN STEP_CODE = 'U18' THEN DATE_COMPLETED
        END) AS STEP_U18,
        MAX(CASE
                WHEN STEP_CODE = '429' THEN DATE_COMPLETED
        END) AS STEP_429
FROM    CLAIMS_STEP_TABLE
WHERE   STEP_CODE IN ('L61','P96','U18','429')
GROUP BY RECORD_ID
,       STEP_DATE

To achieve this result:

 RECORD_ID STEP_DATE STEP_L61  STEP_P96  STEP_U18  STEP_429
---------- --------- --------- --------- --------- ---------
     67555 07-NOV-08           08-NOV-08           15-NOV-08
      9876 05-FEB-08
    123456 05-JUN-07           10-AUG-07
        67 05-MAR-08           10-MAR-08
    123456 05-JAN-09           10-JAN-09

Then your entire query returns the following:

SQL> SELECT  RECORD_ID
  2  ,       MAX(STEP_DATE)
  3  FROM
  4  (
  5          SELECT  RECORD_ID
  6          ,       STEP_DATE
  7          ,       MAX(CASE
  8                          WHEN STEP_CODE = 'L61' THEN DATE_COMPLETED
  9                  END) AS STEP_L61,
 10                  MAX(CASE
 11                          WHEN STEP_CODE = 'P96' THEN DATE_COMPLETED
 12                  END) AS STEP_P96,
 13                  MAX(CASE
 14                          WHEN STEP_CODE = 'U18' THEN DATE_COMPLETED
 15                  END) AS STEP_U18,
 16                  MAX(CASE
 17                          WHEN STEP_CODE = '429' THEN DATE_COMPLETED
 18                  END) AS STEP_429
 19          FROM    CLAIMS_STEP_TABLE
 20          WHERE   STEP_CODE IN ('L61','P96','U18','429')
 21          GROUP BY RECORD_ID
 22          ,       STEP_DATE
 23  )
 24  WHERE   STEP_L61 IS NULL
 25  AND     STEP_P96 IS NOT NULL
 26  AND     STEP_U18 IS NULL
 27  AND     STEP_429 IS NULL
 28  GROUP BY RECORD_ID
 29  /

 RECORD_ID MAX(STEP_
---------- ---------
    123456 05-JAN-09
        67 05-MAR-08

SQL>

HTH!

Tags: Database

Similar Questions

  • I try to insert two images in a single document, group them, and then export it to a jpg file but cannot do so can you please help. Thank you

    I try to insert two images in a single document, group them, and then export it to a jpg file but cannot do

    Hello sara,.

    For my part, I prefer to use my German PS in this way (I try to translate the commands):

    Use the same height for both images.

    Open the first image in PS.

    Use Bild > Arbeitsflache (Image > work plan?) See screenshot:

    From there:

    Give him the new with, by clicking on the left or the right indicating the hand playing around (trial and error).

    Now you can insert your second image.

    Hans-Günter

  • How can I delete large groups of photos and save the ones I want to keep?

    How can I delete large groups of photos and save the ones I want to keep?

    Rickw salvation,

    You must select all the images you want to remove in now CTRL + click in Windows and command-click on Mac.

    Once this is done, you can press the delete button to delete the catalog.

    It will also give you the option to delete the computer as well.

    Please click the link for information detailed below.

    Adobe Photoshop Lightroom Help | Manage photos in folders

    I hope this helps.

    ~ UL

  • How to rotate and save a Digital Photo

    MS Photo Viewer, I cannot save a rotated picture. I have a large number of photos downloaded from my digital camera. Many of them are on their side, that I photographed with the camera rotated because they were more in height as in width. However, when I try to save them in the folder they originate, Windows tells me I can't save the picture, since I do not have access. Because I downloaded a large number of them, I want to be able to view the entire group of them, turning and save the rotated copies so that each image is in the same direction (not a up and some of their side). With photos in the same sense, I can make a slide show, or post it on my screen or TV. What is the best way to accomplish this please?

    Monday, November 10, 2014 00:17:15 + 0000, abradaxis wrote:
     
    > What is the best way to accomplish this please?
     
    It is powerful enough and should do everything you need (and it is the free gift,
    (supported).
     
     
     
    __________________________________________________________________________________________________
    Barb
    MVP Windows Entertainment and connected home
     
    Please mark as answer if that answers your question
     
     
     
  • Problem with the difficulty of opening the old tabs settings and save files when a new session is opened

    Hello
    Since 2 weeks I have a problem: I always set my settings to restore the previous session with all my tabs and I choose that Firefox asks me where I want to save my downloaded files. Now, every time I close Firefox and I open it again, it is not taken into account and 3 tabs are opened: Firefox, Google, and thanks to install Zotero! I spare it, but every time it opens these tabs and not man. Ditto for saving the files. It goes back automatically to open the start page and save my file in the downloads. Even if I spare, it's the same.
    I've desinstalled CCleaner (I thought it might be that), but nothing changes!
    Help, please. Thank you very much!
    Martha

    Here's what I'll try:

    • Reset Firefox - that should solve the problem, but it will change the settings like where files are downloaded and what tabs open at startup back to their default values.
    • Then change your download and back session restore preferences to how you like them.

    Here's how:

    1. Go to help > troubleshooting information.
    2. Click on the button 'Reset Firefox'.
    3. Firefox will close and reset. After Firefox is finished, it will display a window with the imported information. Click Finish.
    4. Firefox opens with all the default settings applied.
    5. Open the window of options - tools > Options > general
    6. In the general Panel set Firefox to open your tabs from last time and set Firefox to ask you where to save downloads.
    7. Click OK

    That should do it. Let me know if it worked.

    Thank you

    Michael

  • Change never forgotten history and save passwords is grey

    New PC Windows 8 and firefox 17.

    I don't seem to be able to save my passwords or other data from the Web site. Under privacy canned or by default in "never remember history" and in respect of the security, remembering passwords button is grayed out. I use firefox for years and never had a problem like this - please help because I do not want to use a different browser

    Thank you both - I am committed a restart of firefox, which seems to have cured the problem. I'll mark as closed and people can also try the reset as if they also have the same problem

    concerning

  • Tools-options-customize-disable 3rd party cookies window is great and save buttons at the bottom of the screen don't show up so I can't change anything or scroll or mak

    Tools-options-customize-disable 3rd party cookies window is great and save buttons at the bottom of the screen don't show up so I can't change anything or scroll, minimize the window somehow

    Hello, please try to start firefox in safe mode - interferes probably an extension or theme...
    Troubleshoot extensions, themes, and issues of hardware acceleration to resolve common problems of Firefox

  • OfficeJet 6110 all-in-one: officejet 6110 all-in-one, window 10, scan and save to PDF

    I always love this printer and do not want to give up yet.  I was able to scan and save to PDF in the window 8 but after upgrade, I am unable to find a driver upgrade to be able to scan and save to the PDF format.  I can only managed to save. TIF, PNG or JPEG.  I need to scan and save to PDF to send an acknowledgement of health to the health care provider.  Any help would be greatly appreciated.

    Yours

    Hello

    Try the HP scanning and Capture app below:

    https://www.Microsoft.com/en-NZ/store/p/HP-scan-and-capture/9wzdncrfhwl0

    So, try the Windows Scan application:

    https://www.Microsoft.com/en-us/store/p/Windows-scan/9wzdncrfj3pv

    Kind regards

    Shlomi

  • Is there a function of block note in Firefox where I can write text/notes and save them in the own record here?

    I have a Dell Inspiron 1525 and if there is a note pad/text tab I don't remember. Firefox system has function that I can take and save notes with everything in, let's say, I created an affiliate campaign?

    Try FoxNotes.

  • My 3.6.14 keeps trying to update and gives this error message: "the update could not be installed. Please make sure that there are no other copies of Firefox running on your computer and restart Firefox to try again. »

    My OS is Windows XP service pack 3 version. I even tried to install FF4 but he never settle. As I mentioned my FF continues to try to update, but it gives the error message that I set out in the title. Now I don't have access to my FF browser and my life stopped because I have all my saved passwords on FF. I restarted my laptop but it stills try to update himself giving the same error message. I can not also improved my Adobe reader 7.0.7-10 I tried more than 10 times, but it is never up to date. I had this problem Adobe for a long time.

    Run the program Firefox once as an administrator (right click: run as administrator).

    If this does not help, then do a clean reinstall.

    Do a clean install (re)-:

    • Download a new copy of Firefox and save the file to the desktop.
    • http://www.Mozilla.com/Firefox/all.html
    • Uninstall your current version of Firefox and remove the Firefox program folder before installing this copy of the Firefox installer.
    • Do not erase personal data if you uninstall the current version.
    • It is important to remove the Firefox program folder to delete all the files and make sure that there is no problem with the files that were the remains after uninstallation.

    Your bookmarks and other profile data is stored elsewhere (not in the Firefox program folder) and will not be affected by a relocation, but make sure that you do not select delete data of a personal nature if you uninstall Firefox.

  • How to incorporate the timestamp and file name automatically select and save the file dialog?

    Hello

    I try to incorporate the name of the file that is the registration of the end user with the timestamp in the selected and save file dialog box. Can you help me?

    Thank you

    Hi Mike227,

    I couldn't find a way to immediately make the bat. I guess you need to mess with ActiveX to do. I found an msdn page that could help with this.

    Have you considered simply concatenating the name of the file and the time stamp with a path of the file and save the file when you create it, without inviting the user?

  • How to customize a VI and save

    I want to customize Auto Power Spectrum.vi and save the modified version.  I put Pwower Spectrum.vi Auto on my pattern, I double click to open it, then I start to change. When I click on file, "save under" is grayed out.  I do not want to save more than the original; I want to do a new and slightly different VI.  How? I use LV 2011. Auto Power Spectum is on the range of spectral analysis of functions Signal Processing Group.

    Thank you.

    It is probably blocked to be re-registered as a part of a kit add-on you paid for.

    Otherwise, you can open the VI, save it under a new name, and then give it to someone.

  • Download and save videa clips of DP on PC card

    I have a camcorder with a PYD card. I can plug the camera on PC and watch the clips but when I try and save and store I get the message that says that Windows cannot open them in Media Player. They will not be displayed in the library or any where that I can play the pictures - if I can play the sound. Help please.

    I have a camcorder with a PYD card. I can plug the camera on PC and watch the clips but when I try and save and store I get the message that says that Windows cannot open them in Media Player. They will not be displayed in the library or any where that I can play the pictures - if I can play the sound. Help please.

    ====================================
    What is the brand and model of your camcorder?

    What is a PYD card?

    What is the (extension) format of video clips?

    Looks like the format of your video clips
    not compatible with Windows Media Player.

    You can download and install a more versatile
    Media player, or you can consider converting
    video clips to a more universal format.

    Another option would be to download and install
    a codec Pack.

  • HP Deskjet 1513: HP Deskjet 1513 - how to scan multiple Pages and save it as a pdf. File

    I am trying to scan several pages (3 pages) and save them all in a single pdf. file.  But, the scanner scans a page at a time and save each separate page as a pdf file. file. I don't see any options in the settings tab for that matter.  How can I scan multiple pages and save them as a pdf. file?  Thank you.

    Hello

    Please try:

    Double-click the icon of the printer on the desktop,
    Select scan a Document or Photo,
    The first page on the glass (face-down)
    Check the options (size, dpi...) and select document Scan to file, (note: not more than 300 dpi).
    Click on Scan - machine will scan the first page
    Delete the first page on the glass, put the second page,
    Click on + (plus sign) it is located on the left side of a red x
    Machine will sweep the second page, put 3rd page on the glass and click on + again... until the end and then click Save
    Click done after save

    Kind regards.

  • Can I download Windows XP and save it to a disk?

    WINDOWS XP / HOME EDITION / 2002 VERSION / SERVICE PACK 3

    Can I download Windows XP Service Pack 3 on the Microsoft site and save it to a disk?
    I was going to wipe my hard drive and reinstall the operating system on my machine, but I don't have the original CD supplied with my machine.
    I was informed by a representative of Microsoft Answers to contact the manufacturer of my machine because windows was preinstalled. After contacting the manufacturer of my machine, the representative told me that I could buy a Windows XP installation CD and install Windows XP on my machine.
    Is it possible to download Windows XP Home Edition / Service Pack 3 on a website and burn it to a CD and then use that CD to reinstall the Windows XP operating system on my machine? That's what I need http://www.microsoft.com/download/en/details.aspx?id=25129
    Thanks in advance for your answer.

    NO, you can not do what you plan to do.

    The files available for download called "Windows XP Service Pack 3" are updated to a full installation of Windows XP.  You can either download an ISO (or 'image') - which is what is your link - or executable file (http://www.microsoft.com/download/en/details.aspx?id=24).

    The ISO file or image is used to create a CD using software able to do this, for example ImgBurn(free).

    In both cases, what you get is the 'service pack' and not the full Windows operating system.

    You need a Windows XP installation CD.  It may be 'gold' (as originally published) or you can find one that integrates the service pack 1 or service pack 2 or service pack 3.  If you get a pre - sp3 installation CD, you will need to update the installation soon after installation.  You can go from sp 1 directly to sp3 without need to install sp2, but if you get an installation CD "gold" you first need to install sp 1 or sp2 before installing sp3.

    Because Microsoft stopped selling Windows XP some time ago, real installation CD are becoming harder to find.

    Although the representative of the manufacturer of your computer is correct that you could buy a Windows XP installation CD and install it, the manufacturer was hired by its license from Microsoft to provide you with a method of re-installing Windows when you purchased the computer.  This may have been a restore partition hidden on your hard drive or a CD/DVD that came with your computer.  I guess that you have lost or damaged what was initially provided so the manufacturer is more able or do not want to replace it with a CD.

    Here are some tips of long date MS MVP PA Bear:

    HOW TO get WinXP SP1 or SP2 fully patched after a 'clean install': http://groups.Google.com/group/Microsoft.public.WindowsXP.General/MSG/a066ae41add7dd2b

    1. download & save the installer for WinXP SP3 on your desktop:
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=5b33b5a8-5E7...

    [Yes, you can jump SP2 if you run WinXP SP1.]

    2. read & take into account:
    http://msmvps.com/blogs/harrywaldron/archive/2008/05/08/Windows-XP-SP...

    3 connected as long as administrator, if necessary, double-click the saved file to install WinXP SP3.  Follow the prompts. Be patient and restart twice when the installation ends.

    4. make the resolution method 2 here (believe me):
    http://support.Microsoft.com/kb/943144

    5. go to http://windowsupdate.microsoft.com . Install all required software, and then click CONTINUE. Select CUSTOM and scan | Install the critical updates of security offered. Still, follow all the instructions.

    [I do NOT recommend install IE7 through Windows Update.]

    6. make sure that automatic updates is enabled; FC.
    http://support.Microsoft.com/kb/306525

    Other references:

    Free unlimited installation and compatibility support is available for Windows XP, but only for the Service Pack 3 (SP3), until April 14-09. Chat and e-mail support is available only in the United States and the Canada.

    Go to http://support.microsoft.com/oas/default.aspx?gprid=1173 . Select "Windows".
    XP"and select"Windows XP Service Pack 3 "

    5 steps to help protect your new computer before going online
    [installation clean = new computer]
    http://www.Microsoft.com/protect/computer/advanced/XPPC.mspx

    Measures to help prevent spyware
    http://www.Microsoft.com/protect/computer/spyware/prevent.mspx

    How TO get Windows XP Gold fully patched: http://groups.Google.com/group/Microsoft.public.windowsupdate/MSG/3f5afa8ed33e121c

    1. download & save the WinXP SP2 installer on your desktop:
    http://www.Microsoft.com/downloads/details.aspx?FamilyID=049c9dbe-3b8...

    [Yes, you can jump SP1]

    1B. download & save the installer for WinXP SP3 on your desktop:
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=5b33b5a8-5E7...

    2. read & take into account:
    http://msmvps.com/blogs/harrywaldron/archive/2008/05/08/Windows-XP-SP...

    3. administrator, if necessary, double-click the saved file to install Windows XP * SP2 *.  Follow the prompts. Be patient and restart twice when the installation ends.

    3B. logged on as administrator, if necessary, double-click the saved file to install WinXP SP3.  Follow the prompts. Be patient and restart twice when the installation ends.

    4. make the resolution method 2 here (believe me):
    http://support.Microsoft.com/kb/943144

    5. go to http://windowsupdate.microsoft.com . Install all required software, and then click CONTINUE. Select CUSTOM and scan | Install the critical updates of security offered.  Still, follow all the instructions.

    [I do NOT recommend install IE7 through Windows Update.]

    6. make sure that automatic updates is enabled; FC.
    http://support.Microsoft.com/kb/306525

    References with dubbing:

    Free unlimited installation and compatibility support is available for Windows XP, but only for the Service Pack 3 (SP3), until April 14-09. Chat and e-mail support is available only in the United States and the Canada.  Reach
    http://support.Microsoft.com/OAS/default.aspx?gprid=1173 | Select "Windows".
    XP"and select"Windows XP Service Pack 3 "

    Protect your PC!
    http://www.Microsoft.com/athome/security/computer/default.mspx

    Learn how to protect your PC by taking the three simple steps
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=3AD23728-497...

Maybe you are looking for