find the most recent value based on the defined date

Hi all

In my example below, I want to find the last symptom and the name that was added after 24-mar-2012 (not before that). Not getting not good performance




with xx as
(select 101 as the ID, "A01" as name, 24 March 2012 ' than double create_date)
Union of all the
Select 101, "A01", March 24, 2012 "of the double
Union of all the
Select 102, "A02", March 24, 2012 "of the double
Union of all the
Select 101, "A01", March 30, 2012 "of the double
Union of all the
Select 102, "A02", March 30, 2012 "of the double
Union of all the
Select 102, "A01", April 21, 2012 "of the double
Union of all the
Select 101, "A01", April 22, 2012 "of the double

),

XY as
(select 101 as the ID, "Asthma" as a symptom of double
Union of all the
Select 101, 'cancer' of the double
Union of all the
Select 101, 'bpressure' from dual
Union of all the
Select 102, 'sbp' of the double
Union of all the
Select 101, 'BPD' of the double
Union of all the
Select 102, 'allergy' of the double
Union of all the
Select 103, "heart failure" of the double
Union of all the
Select 102, 'sneezing' from dual

)

Select xx, xy, xx.name, xy.symptom, xx.create_date
where xx.id = xy.id
Group of xx.name, xy.symptom, xx.create_date
"After having xx.create_date > 24 March 2012"
with xx as
(select 101 as ID, 'A01' as name, '03/24/2012' as create_date from dual
union all
select 101, 'A01', '03/24/2012' from dual
union all
select 102 , 'A02', '03/24/2012' from dual
union all
select 101 , 'A01', '03/30/2012' from dual
union all
select 102 , 'A02', '03/30/2012' from dual
union all
select 102 , 'A01', '04/21/2012' from dual
union all
select 101 , 'A01','04/22/2012' from dual

),

xy as
(select 101 as ID, 'asthma' as symptom from dual
union all
select 101 , 'cancer' from dual
union all
select 101 , 'bpressure' from dual
union all
select 102, 'sbp' from dual
union all
select 101 , 'dbp' from dual
union all
select 102, 'allergy' from dual
union all
select 103 , 'cardiac failure' from dual
union all
select 102 , 'sneezing' from dual

)

select xx.name, xy.symptom, xx.create_date from xx, xy
where xx.id=xy.id
and substr(xx.create_date,4,2)>24
group by xx.name, xy.symptom,xx.create_date;

Tags: Database

Similar Questions

  • Find the minimum date on multiple columns

    Hello

    I have two questions to find the minimum date on several columns:
    1. need a select query that should JOIN two tables and return any information (CASSEDTL) table with minimum date out of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE.
    2. need of an update query that should update all cases in the CASEDTL table with the minimum date of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE.

    The DDL:
    CREATE TABLE CASEMSTR 
    (   CASENBR     NUMBER,
        DATEISSUED  DATE,
        DATEPLACED  DATE,
        DATEENTERED DATE);
        
    CREATE TABLE CASEDTL 
    (   CASENBR     NUMBER,
        STATDATE    DATE,
        RCVDATE    DATE,
        MODDATE     DATE);
        
    INSERT INTO CASEMSTR VALUES (1, '1 JUL 2007', '1 JUL 2007', '12 JUL 2007');
    INSERT INTO CASEMSTR VALUES (2, '1 JAN 2008', '1 JAN 2008', '21 JAN 2008');
    INSERT INTO CASEMSTR VALUES (3, NULL, NULL, '3 DEC 2008');
    INSERT INTO CASEMSTR VALUES (4, '31 MAR 2009', NULL, '6 APR 2009');
    INSERT INTO CASEMSTR VALUES (5, NULL, '22 MAR 2009', '6 APR 2009');    
    INSERT INTO CASEMSTR VALUES (6, NULL, NULL, '16 JUL 2009');
    INSERT INTO CASEMSTR VALUES (7, '1 DEC 2008', '7 DEC 2008', '26 DEC 2008');
    INSERT INTO CASEMSTR VALUES (8, NULL, NULL, '17 MAY 2009');
    
    INSERT INTO CASEDTL VALUES (1, '25 JUN 2007', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (2, '1 JAN 2008', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (3, '11 NOV 2008', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (4, '31 MAR 2009', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (5, '19 JUL 2009', NULL, '2 AUG 2009');    
    INSERT INTO CASEDTL VALUES (6, '13 JUN 2009', NULL, '16 JUL 2009');
    INSERT INTO CASEDTL VALUES (7, '7 DEC 2008', NULL, '16 JUL 2009');
    INSERT INTO CASEDTL VALUES (8, '14 MAY 2009', NULL, '16 JUL 2009');
    COMMIT;
    The initial query I have is
    SELECT CD.CASENBR, CM.DATEISSUED, CM.DATEPLACED, CM.DATEENTERED, CD.STATDATE, CD.RCVDATE, NULL "NEW RCV DT" 
    FROM CASEDTL CD
        INNER JOIN CASEMSTR CM
            ON CD.CASENBR = CM.CASENBR;
    Need to know what is the best way to complete the new Date of RRS? Receive a new date should be the minimum date of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE. And also how do I write an update statement unique to upade date of receipt in the detail table?

    Any help would be appreciated! Thanks in advance!

    Where is the function LESS? Refer to manual SQL.

    HTH - Mark D Powell.

    put1 > desc multdate
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     COL1                                               DATE
     COL2                                               DATE
     COL3                                               DATE
    
    put1 > select * from multdate;
    11-AUG-09 10-AUG-09 01-AUG-09
    
    put1 > select least(col1, col2, col3) from multdate;
    01-AUG-09
    

    Published by: MarkDPowell on August 11, 2009 15:53 added example

  • How can I recharge my favorites if I can't find the file "date.json" in my backup?

    My hard drive crashed and everything had to be recovered and reinstalled. I have a data folder Firefox but can not find the file "date.json" which is indicated to open the troubleshooting instructions. Y at - it another option?

    Hello

    If you have the latest version of Firefox, the file places.sqlite is what keeps your bookmarks. See the article for recovery of data from an old profile for more information.

  • Cannot find the release date of a film that I pre-ordered.

    I can't find the release date of a film that I pre-ordered.

    It is possible that the movie studio/owner of the rights has not yet established a real date, when we know that it should show on your account: pre-order music and movies on the iTunes Store - Apple Support

  • I just bought the SX710 HS. Cannot find the stamp date on the Menu. Is there a?

    I just bought the SX710 HS.  Cannot find the stamp date on the Menu.  Is there a?

    It seems strange, but no, I don't think that you can mark the date on the pictures. You can print the with a good date.

  • Error: Could not find the locale data files. Please reinstall when you try to open Facebook.

    Original title: locale data file errors... How can I fix it?

    can't the facebook home page and when I search the

    "Cannot find the locale data files. Please reinstall"pop box.

    Hi kjkin,

    1 did you change on your computer before this problem?

    2 are you able to access other Web sites correctly?

    3. what browser do you use?

    If you are using Internet Explorer, follow these methods & check if the problem persists:


    Method 1

    You can follow this link & check if the problem occurs:

    Can't access some Web sites in Internet Explorer


    Method 2

    You can also follow this link:

    How to delete the contents of the temporary Internet files folder?


    Reference:
    Internet Explorer does not start or stops responding

    Hope the helps of information.

  • Cannot find the locale data files. Please reinstall

    I had a problem with Google Chrome, so I uninstalled via the control panel. I then reinstalled and I have this problem. I always present in my programs in the watched folder, but when I select to demolished, he said ' wait until the current program has finished install or changing.» I have no other program install or change. If I try to open Google, anywhere Progams, taskbar, all programs or directly from the .exe LocalApps it gives me the "could not find the locale data files. Please reinstall.

    I found the answer to my question. It seems that you can build processes, I don't understand why. For example I had a problem with my windows Explorer crashing. I disabled all the startup process of msconfig.

    In my view, there must be something in there that closes a completed process.
    Then I had, unknown to me, when I posted this problem, six or seven cases Google chrome showing the the Task Manager process tab. When I quit all instances of Google, I was able to finish the removal process and re - install Google Chrome.
    I just checked right now and I have six Google shown 3 rundll32.exe and two taskeng.exe bodies. I've never seen no more than one instance of anything in this tab before today.
    Disabling all startup stuff does not solve my problem to explore some way so I'll allow them once again.
    Thank you for helping me and I hope that someone can get useful information from my travels.

  • Where we can find the attachment data type short text

    Hello

    file type attachments are store at fnd_lob.

    Where we can find the attachment data type short text in oracle apps.

    Concerning

    Hello

    Thanks, that's useful.

  • Cannot find the MAX Date value in the USER_TAB_PARTITIONS HIGH_VALUE

    Hi all

    I'll try to find the Max value of the date of the HIGH_VALUE from the USER_TAB_PARTITIONS, but my request has failed because the HIGH_VALUE is a LONG column.

    Appreciate your valuable contributions here.

    Thank you
    MK.

    Maldini says:
    I'll try to find the Max value of the date of the HIGH_VALUE

    You use the PL/SQL:

    SQL> select  high_value
      2    from  user_tab_partitions
      3    where table_name = 'RANGE_SALES'
      4  /
    
    HIGH_VALUE
    ----------------------------------------------------------------------------------------------
    TO_DATE(' 1998-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1998-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1998-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    
    HIGH_VALUE
    ----------------------------------------------------------------------------------------------
    MAXVALUE
    
    12 rows selected.
    

    Now:

    create or replace
      type DateList
        as
          table of date
    /
    declare
        v_DateList DateList := DateList();
        v_max_high_value date;
    begin
        for v_rec in (select high_value from user_tab_partitions where table_name = 'RANGE_SALES') loop
          if v_rec.high_value != 'MAXVALUE'
            then
              v_DateList.extend;
              execute immediate 'begin :1 := ' || v_rec.high_value || '; end;'
                using out v_DateList(v_DateList.count);
          end if;
        end loop;
        select  max(column_value)
          into  v_max_high_value
          from  table(v_DateList);
        dbms_output.put_line('Table RANGE_SALES max high value is ' || to_char(v_max_high_value,'MM/DD/YYYY HH24:MI:SS'));
    end;
    /
    Table RANGE_SALES max high value is 10/01/2000 00:00:00
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Error message: ' the money is corrupt or not a Money data file. " Make sure that you open a file with a MNY extension. "If you have chosen the correct file and are not accessible, you will need open your most recent backup file to access your data.

    Hi just updated my pc at home for Window XP Professional 2002 with Office 2007.  Re-installed Money99 and progam opens fine, but I can't recover my files of saved Money and the aforementioned error keeps popping up.  Help please.

    Thank you

    Hello
     
    Your problem is related to Microsoft Money and would be better suited in the Microsoft Money forum. I would like you to post your question in the forum that supports your problem.
     
     
    Aziz Nadeem - Microsoft Support

    [If this post was helpful, please click the button "Vote as helpful" (green triangle). If it can help solve your problem, click on the button 'Propose as answer' or 'mark as answer '. [By proposing / marking a post as answer or useful you help others find the answer more quickly.]

  • How to find the last date of execution of the objects in database

    Hi all

    We're going for an upgrade of the database 11g and for the same thing, we want to know the last date of the following-

    Packages, Tables, views
    Conc. programs / value Sets / look up / profile options

    Is there a way we can find the same thing.
    The answers would be really useful.

    Kind regards
    Shruti

    So can you provide clues on how to find the last opportunity registration

    I don't think you can find such a script with having activated audit.

    Thank you
    Hussein

  • SQL to find the same DATE?

    I wanted to do a check based on a Table of 10g.

    customer_id, DATE

    Basically, I wanted to do a check, make sure that each customer_id has a SEPARATE DATE, therefore, for the returned data.
    the DATE must be unique and not repeat, I know its probably something super simple, but I wanted to analyze the entire
    table and do a count of these instances:

    It would be nice:

    12345 20101001
    25487 20101002

    This would not be permitted:

    12345 20101001
    12345 20101001 - double date
    25487 20101002

    a varchar2 column, it is in format YYYYMMDD, not not using type DATE, just FYI. Ago, I know, I have not said that upward.

    I would use a SELF JOIN here, not a lot of experience in this.

    Hello

    Here's one way:

    WITH     got_cnt          AS
    (
         SELECT     customer_id
         ,     dt          -- DATE is not a good column name
         ,     COUNT (*) OVER ( PARTITION BY  customer_id
                                    ,              dt
                        )      AS cnt
         FROM    table_x
    )
    SELECT    *
    FROM       cot_cnt
    WHERE       cnt     > 1
    ORDER BY  customer_id
    ,            dt
    ;
    

    A self-join anouther way to find duplicates, but may not be as effective. In addition, what would you like if it was be stored 3 (or more) with the same customer_id and dt?

    Published by: Frank Kulash, October 21, 2010 16:44

    Oh!
    If you want to display the columns are duplicated, you can do something even more fast and simlpler:

    SELECT       customer_id
    ,       dt
    ,       COUNT (*)     AS cnt
    FROM       table_x
    GROUP BY  customer_id
    ,       dt
    HAVING       COUNT (*)     > 1
    ;
    
  • [JS] I would like to find the modifed date of a link file

    I have a vbs script that updates my links. It checks if the file already exists and then the modified date. I need to check that the binding file had been updated in a few hours to ensure that it has information of today instead of yesterday.

    I would like to convert this option to use JavaScript, but have struggled to find the date of change of the link.

    I don't expect someone to rewrite my script, but if someone can give an example to find if a file exists, and it changed the date?

    Terry W.

    Option Explicit

    MsgBox "press OK to continue."

    'object console application '.
    Dim objMyInDesign
    ' ofject document
    Dim objMyDocument
    ' table object
    Dim objTable
    ' cell object
    Dim objCell
    Dim txtNewText
    ' connection object
    Dim objMyLink
    Dim txtFlag

    "File of the file system object.
    Dim objFSO
    Dim objFileExistMessage
    Dim objFile
    Dim TimeDifference
    Dim FileDate

    ' Test for the Message box
    Dim MessageText

    ' myDocument will be the active document
    Dim myDocument

    ' Object of Windows Script
    Dim WScript

    Set objFSO = CreateObject ("Scripting.FileSystemObject")

    Set objMyInDesign = CreateObject ("InDesign.Application.CS3")

    If objMyInDesign.Documents.Count = 0 Then
    MsgBox ("Please open the Document and try again.")
    On the other
    Set objMyDocument = objMyInDesign.ActiveDocument

    DoLinksExist()
    ' ProcessLinks()
    End If

    Void DoLinksExist
    For each objMyLink in objMyDocument.Links
    If not objFSO.FileExists (objMyLink.FilePath) and

    (The TypeName (objMyLink.parent) <>"BPA") Then
    objFileExistMessage = MsgBox ("' file/link does not exist:" ")

    & _ vbCrLf
    & vbCrLf & _ objMyLink.FilePath & vbCrLf & vbCrLf
    & "Do you want to continue with missing files?", _
    vbYesNo + vbCritical, "lack of Stock - continue?')"

    If objFileExistMessage = vbYes then
    FilesAge()
    Exit Sub
    Else if objFileExistMessage = vbNo then
    MsgBox ("Script Quiting!")
    Exit Sub
    End If
    End If
    Next
    FilesAge()
    End Sub

    Void FilesAge()
    For each objMyLink in objMyDocument.Links
    If objFSO.FileExists (objMyLink.FilePath) and

    (The TypeName (objMyLink.parent) <>"BPA") Then
    Set objFile = objFSO.GetFile (objMyLink.FilePath)

    TimeDifference = abs (DateDiff ('h', now))

    objFile.DateLastModified))
    ' If the file is longer than six hours may present error

    Message
    If TimeDifference > 6 may
    objFileExistMessage = MsgBox ("ATTENTION!" _
    & vbCrLf & "OLD." OLD! _ OLD! »
    & vbCrLf & _ vbCrLf
    And "A Stock is very OLD" & _ vbCrLf
    & vbCrLf & vbCrLf & objMyLink.FilePath &

    _ + "\n"
    & "Do you want to take old stocks on.

    page? », _
    vbYesNo + vbCritical, "OLD STOCKS-

    Continue? »)
    If objFileExistMessage = vbYes then
    ProcessLinks()
    Exit Sub
    Else if objFileExistMessage = vbNo then
    MsgBox ("Script Quiting!")
    Exit Sub
    End If
    End If
    End If
    Next
    ProcessLinks()
    End Sub

    Void ProcessLinks
    For each objMyLink in objMyDocument.Links
    If objFSO.FileExists (objMyLink.FilePath) and

    (The TypeName (objMyLink.parent) <>"BPA") Then
    objMyLink.Update
    On the other
    ' objFileExistMessage = MsgBox ("the file/link

    _ Does NOT exist.
    "& vbCrLf _
    "& _ vbCrLf & objMyLink.FilePath
    "& vbCrLf & vbCrLf &"this link will not "

    _ processed ".
    ' & + "\n" & vbCrLf & "click 'OK' and ' _
    "&"script will continue processing

    files/links')
    End If
    Next
    End Sub

    Oh, and all the information above (with the exception of rambling thoughts) was found with searches by key words simple index.

    Can I interest you in a more user-friendly help (at the same time to work with and for the eyes)? See http://www.jongware.com/idjshelp.html.

  • Find the Oracle data source...

    I inherited a ColdFusion 10 app with a backend Oracle 11g; Windows Server.    I am especially a DBA and not an expert in ColdFusion.  In the application code, they have the hardcoded data source.  In other words, when I move to Test I have to change the source data, load the modules and test.   After a successful test, I need to change the data source, once again, to download and the promoted to production.   I seem to remember in the old application, I used to support, the code was generic and the data source depends on what server you were lit; If the development, testing or production, you don't have to worry.  I don't remember how it was done.   What would be the best way to eliminate this hard coding and make it more automated?   I know I'm probably missing something, but you were all very helpful to me in the last few weeks, so I hope that he is not a stupid question.   Thank you.

    I do not have Admin CF

    You can specify that?  Do you mean that you do not have access to the CF Admin?

    Not having access to the CF Admin, I'm not sure you can do something differently as you are now., unless you're writing a logic to examine the server host name or the domain name of the site and set the source of data accordingly.

    If you can access the CF Admin, create two data sources: one for production and one for testing.  Then in application.cfc, you can write logic to examine the server host name or the domain name and indicate 'this.datasource' to whatever datasource is appropriate.

    -Carl V.

  • How to find the expiry date of the contract and how to contact the support [was: I need to talk to someone please]

    How will I know how many time I paid for my CC Pro first? How will I know when my contract fiinished? How will I know if I ve bought a new contract (without notification)?

    I´d would like to know how can I find out how long I ve this contact.

    Manage your membership and your payment. Creative cloud

    https://helpx.Adobe.com/x-productkb/policy-pricing/membership-subscription-troubleshooting-creative-cloud.html

    For contact, for the link below click on the still need help? option in the blue box below and choose the option to chat or by phone...

    Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache.  If it fails to connect, try to use another browser.

    Creative cloud support (all creative cloud customer service problems)

    http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN )

Maybe you are looking for

  • Re: Satellite L855 - max with newer SSD speed

    I am looking to buy this mobile+ The message was edited: broken link has been removed. (Croatian language, but will help) I wonder if it is SATA 6 Gbit/s so I can buy newer SSD to use max speed? Thank youMario

  • My music all sounds as if it was in an echo chamber.

    original title; My music all sounds as if it was in an echo chamber. This is a first, has never sounded like this before. don't know what happened. Can you help me? My music all sounds as if it was in an echo chamber. This is a first, has never sound

  • Problem WET610N

    Hi, I got WET610N this week and work very well. I use it on a T, and works very well, but after a few days was inaccessible. Then I tried to update firmware, and I had a lack of power during the process. Result: the bridge will not respond to try to

  • Computer DV7-1825dx laptop screen turns off at least connected to the HDMI

    I have a Pavilion dv7-1825dx running Windows Vista Home Premium 64-bit.  The other day, I simply closed the laptop into hibernation.  At the time, it was only connected to a printer and a wireless mouse.  The next day, I opened the laptop and it turn

  • Application with no standardized and the stress of missing foreign key in database

    Hi allWe bought Asset Tracking System of a local company. They developed in Oracle Developer Suite 6i Asset Tracking System and database is Oracle 10g in the Ms Windows environment.the database provided by the company had a problem. I send the compan