SQL logic or loops to find this

Hello

(Frank: modified requirements of else query I posted yesterday why you gave the right answer)

Here are the SQL statements...

Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.6,to_date('08-08-2008 12:40:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.5,to_date('08-08-2008 15:44:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.4,to_date('09-08-2008 10:58:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.8,to_date('10-08-2008 07:19:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.4,to_date('11-08-2008 06:55:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.2,to_date('12-08-2008 08:12:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.4,to_date('15-08-2008 18:11:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.2,to_date('31-05-2009 13:25:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.4,to_date('01-06-2009 08:27:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.5,to_date('02-06-2009 07:55:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.7,to_date('11-02-2010 17:48:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.5,to_date('23-05-2010 00:20:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.3,to_date('08-06-2010 12:59:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',0.7,to_date('10-08-2010 19:23:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.4,to_date('04-10-2010 14:16:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.7,to_date('09-02-2011 22:53:00','DD-MM-YYYY HH24:MI:SS'));
Insert into X (MEDICAL_RECORD_NUMBER,VAL,RESULT_DATE) values ('1076789',1.8,to_date('29-09-2011 19:37:00','DD-MM-YYYY HH24:MI:SS'));


Output:

MNR DATE1 DATE 2

1076789 08/08/2008 15:44 08/15/2008 18:11

1076789 31/05/2009 13:25

Process.

(1) I need to go through all the records in ascending order.

(2) find the first record where the difference between the values is > = difference of 0.3 and the date is < = 48 hours

(3) in the above: 08/08/2008 15:44 has an increase of 0.3 compared to the record of 4.

(4) so keep the date from point 3.

(5) now must find the peak value within 14 days from 08/08/2008 15:44

(6) as soon as we have the date starting from which we have the peak value, (which is 10-08-2008 07:19 for value 1.8)... . I need to move through the records following until I find 3 consecutive records that can be found on * DIFFERENT * days to have all 3 records

a drop of > = 0.3 between 1.8 and get the 3rd date

(similar to the thread from yesterday: user7431648 )

If there are 2 folders that are located on the same day, you must consider the 1st date of registration (minimum) that meets the criterion of 0.3.
Ex: here, in the scenario above, after we had a peak at 1.8 on 08/10/2008-07:19, we have 3 files consecutively

2008-11-08 06:55

2008-12-08 08:12

2008-08-15 18:11

for which the difference compared to the peak is > = 0.3.

Then choose the 3rd date or 2 Date in the output... 2008-08-15 18:11

(7) now repeat the whole process of items 1-6 after 15/08/2008 18:11 (below)

(8) so that, the next is 31/05/2009 13:25

(9) the peak within 14 days from 31/05/2009 13:25 is on 2009-02-06 07:55 for which there is an increase of 0.3.

(10) after 2009-02-06 07:55 there is no drop of > = 0.3 to 3 consecutive records.

(11) so there is no Date 2 in the output for it.

Let me know if any part is not clear.

Thank you

REDA

1076789

Hello

I found my mistake.  In the subquery got_dates_1_2 at the join condition for the table l, there is a scalar subquery that is corellated to e table.  It must be put into correlation by result_date and medical_record_number, but I left out the medical_record_number above.  I added 1 line (line 33, marked "* NEW * below"), and now it's the production of correct results.

WITH got_day_vals AS

(

SELECT TRUNC (result_date) AS trunc_result_date

MIN (result_date) DUNGEON (DENSE_RANK FIRST ORDER BY val)

AS min_result_date

MAX (MIN (val)))

PARTITION BY medical_record_number

ORDER BY TRUNC (result_date)

LINES BETWEEN 2 PRIOR

AND CURRENT ROW

) AS high_val_3_day

medical_record_number

X

GROUP OF TRUNC (result_date)

medical_record_number

)

got_dates_1_2 AS

(

SELECT e.medical_record_number

e.result_date AS date1

l.min_result_date AS date2

ROW_NUMBER () TO)

PARTITION BY e.medical_record_number

ORDER BY e.result_date

l.min_result_date

) AS r_num

X e

JOIN x p WE p.val =)

SELECT MAX (val)

X

WHERE the result_date BETWEEN e.result_date

AND e.result_date + 14

AND medical_record_number = e.medical_record_number-* NEW *.

)

AND p.result_date BETWEEN e.result_date

AND e.result_date + 14

AND p.medical_record_number = e.medical_record_number

LEFT JOIN got_day_vals l I l.high_val_3_day<= p.val="" -="">

AND l.min_result_date > p.result_date

AND l.high_val_3_day<= greatest="" (="" p.val="" -="">

, p.val / 2

)

AND l.medical_record_number = e.medical_record_number

WHEN THERE IS)

SELECT 1

X

WHERE (val > = e.val +.3)

AND result_date BETWEEN e.result_date

AND e.result_date + 2

AND medical_record_number = e.medical_record_number

)

OR (val > = e.val * 1.5)

AND result_date BETWEEN e.result_date

AND e.result_date + 7

AND medical_record_number = e.medical_record_number

)

)

)

got_next_r_num AS

(

SELECT d.

,       (

SELECT MIN (r_num)

OF got_dates_1_2

WHERE medical_record_number = d.medical_record_number

AND date1 > = d.date2

) AS next_r_num

OF got_dates_1_2 d

)

SELECT medical_record_number, date1, date2

OF got_next_r_num

START WITH r_num = 1

CONNECT BY medical_record_number = PRIOR medical_record_number

AND r_num = PRIOR next_r_num

ORDER BY medical_record_number

date1

;

Tags: Database

Similar Questions

  • SQL logic or missing database error

    What is the problem with this statement

    INSERT INTO tableName(CID,TITLE)VALUES(1,test)
    

    I get the error "SQL logic error" or missing database

    I managed to solve it by using bind

  • Dashboard OBIEE - JavaScript - get the SQL logic

    Hi Experts,

    I have the dashboard with an OBIEE report and dashboard invites. So, whenever I change the values in the prompt lines in the report to amend accordingly. I hope that the sql logic changes also to the selection, I do on the dashboard page.

    I want to take this logical sql update. I knew that we can write the javaScript function in the municipality. JS file and then call this function in the dashboard. But I want to know how I can get the update sql logic.

    Any help or inputs would be appreciated.


    Thanks and greetings
    S

    Hi Siva,

    Sorry about that last post. I did not properly escape all my special characters and the Forum diverted.

    I have corrected the errors and again tested the code. Works fine on IE and Moilla.

    Give it another shot.

    -Joe

  • I receive a notice indicating that cant find this url

    I tried to put in the www, µcard. but it just says: cant find this do URLs that I need to enable something or install something I don't want to reset the browser from mozilla

    Hello

    Try access via this link:

    Also:

  • Thanks for the update of Firefox 4. Here is my concern - previously, the option "Search for updates" is located under the Help menu. In Firefox 4, I can't find this option; How will we be able to check if there are updates available?

    Previously, the "Find updates" option is located under the Help menu. In Firefox 4, I can't find this option; How will we be able to check if there are updates available?

    Can this new version to update automatically? How to set this option?

    Click the Firefox button, click Help, click on Firefox, there is a control for the button updates on this screen.

    Other issues that need your attention

    The information provided with your question indicates you have outdated plugins with known security and stability issues that need to be updated. To see the plugins submitted with your question, click on "+ system details...". "to the right of your original message of the question. You can also see your plugins in the Firefox menu Tools > Modules > Plugins.

    • Adobe Shockwave for Director Netscape plug-in, version 11.5

      • Several security updates behind
    • Adobe PDF plugin for Firefox and Netscape
      • Seems to be an older version
    • Shockwave Flash 10.2 r152
      • 10.2 r153 recently released security update
    • Next-generation Java plug-in for the Mozilla browsers 1.6.0_15
      • 9 updates behind
    1. Check your plugin versions on one of the following links:

    2. Update to Shockwave for Director
      • NOTE: this is not the same thing as Shockwave Flash; This installs the Shockwave Player.
      • Use Firefox to download and SAVE the installer to your hard drive from the link in the article below (Desktop is a good place, so you can find it).
      • When the download is complete, exit Firefox (file > exit)
      • Locate and double-click it in the installer that you just downloaded, let the complete installation.
      • Restart Firefox, and look at your plugins.
      • Download link and more information: http://support.mozilla.com/en-US/kb/Using+the+Shockwave+plugin+with+Firefox
    3. Update of Adobe Reader (PDF plugin):
      • Within your existing Adobe (If you have already installed) drive:

    • Open the Adobe Reader program in your list of programs
    • Click Help > check for updates
    • Follow the instructions to update
    • If this method works for you, go to the section "download full installer ' below and go to"after the installation"below
  • Download the full installer (If you have NOT installed Adobe Reader):
    • "Use the links below in order to avoid the painful' getplus" Adobe Download Manager and other 'extras' you do not want
    • Use Firefox to download and SAVE the installer to your hard drive for the appropriate link below
    • Click "save to file"; Save to your desktop (so you can find it)
    • Once the download is complete, close Firefox
    • Click on the installation program, you just downloaded and allow installation to continue
      • Note: Vista and Win7 users need to right click on the installer and choose "Run as Administrator"
    • Download link: ftp://ftp.adobe.com/pub/adobe/reader/
      • Choose your operating system
      • Choose the latest version of # .x (example 9.x for version 9)
      • Choose the version the most recent number
        • NOTE: 10.x is the new Adobe Reader X (Windows and Mac only from this announcement)
      • Choose your language
      • Download the file, save it to your hard drive, when finished, close Firefox, click on the installation program you just downloaded and let it install.
      • Windows: click on the .exe file. Mac: click on the .dmg file
  • Using one of the links below will force you to install the "getPlus" Adobe Download Manager
  • . Also don't forget to uncheck the McAfee scanner if you do not want the link force installed on your desktop computer
  • After installation, launch Firefox and recheck your version.
  • Update the Flash plugin to the latest version.
    • Download and SAVE to your desktop, so you can find the Setup program later
    • If you do not have the current version, click on the "Player Download Center" link on the 'download and information' or 'Download manual installers' below
    • Once the download is complete, exit Firefox
    • Click on the installer, you just download and install
      • Windows 7 and Vista: will need to right click on the installer and choose 'run as administrator '.
    • Launch Firefox and recheck your version or up to the download link below to test the installation
    • Download and information: http://www.adobe.com/software/flash/about/
      • Use Firefox to go to the site above to update the Firefox plugin (will also install the plugin for most other browsers, except IE)
      • Use IE to go to the site above to update the ActiveX to IE
    • Download manual installers.
  • Update the Java plugin to the latest version.

  • See also "Manual Update" in this article for update from the Java Control Panel in Control Panel: http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates
  • Removal of older versions (if required): http://www.java.com/en/download/faq/remove_olderversions.xml
  • Remove several extensions of Console Java (if necessary): _ http://kb.mozillazine.org/Firefox: _FAQs_:_Install_Java #Multiple_Java_Console_extensions
  • Java test: http://www.java.com/en/download/help/testvm.xml
  • Impossible to find this Satellite L670D - 14 p on the registration page

    Hello

    I bought a laptop: Satellite L670D - 14 p and one can't find this one on the registration page (does not appear in the list).
    How can I do to make the guarantee?

    I live in Wallis (Wallis and Futuna in Pacific Island) and this country does not appear in the list too.
    I have another problem, when I try to register my laptop (when I write the date of purchase) I got a message in red.
    Alternatively, it takes 3 weeks for the laptop to arrive at Wallis after the purchase.

    Thank you for your help

    Sincerely

    > I live in Wallis (Wallis and Futuna Island in the Pacific) and this country does not appear in the list too.
    Wallis and Futuna Island in the Pacific? WOW what a great place

    In any case, not this area belongs not to the EMEA region.

    Satellite L670D - 14 p PSK3JE-08H005FR belongs to the European series of Toshiba and my knowledge, standard warranty is valid only for the countries in the EMEA region.
    http://EU.computers.Toshiba-Europe.com/innovation/services/standard-warranty/

    Here you can find the PDF EMEA warranty info.
    http://goo.GL/wN1mS

  • Removal of Library/Cookies/com.apple.appstore.plist. Where can I find this file to delete?

    According to TechTool Pro, I have a corrupted file - /utilisateur/ (my name)/Library/Cookies/com.apple.appstore.plist. Where can I find this file to delete?

    Thank you

    Rob

    Choose go to folder from the Finder Go menu and paste into ~/Library/Cookies/ as the path.

    (139945)

  • I bought the iphone 6 s more time face in Saudi Arabia. I need to check if the original phone to apple or duplicated. So please help me find this problem.

    I bought the iphone 6 s more time face in Saudi Arabia. I need to check if the original phone to apple or duplicate. So please help me find this problem.

    Hey there, I guess your question is "how to determine if my iphone is true or false. If Yes, then if you go here https://selfsolve.apple.com/agreementWarrantyDynamic.do just enter your serial number and code and if his 'real', then it will show you the model of the Iphone and guaranteed dates. If this isn't the case, then you know the rest. If this is not the case then try to download apps from the app store and run or can it connect to itunes. Tell me what best worked: D - Jon

  • Where is Windows Clipboard files? What directory? I was not able to find this information. I want to get back to a previous screen printing.

    Where is Windows Clipboard files? What directory? I was not able to find this information. I want to get back to a previous screen printing.
    I didn't not turn off my computer and I did 3 other print screens after that I want to get back because I didn't stick it in Paint by mistake.

    The clipboard objects are not stored in a file. When you send something to the Clipboard, it is stored in a memory location that is only available for the operating system.

    A web search will find 3 third-party programs that will allows to record multiple Clipboard entries. Research on '' programs Clipboard. '' Microsoft® Security MVP, 2004-2009

  • Error message: "cannot find this file" and songs seem to disappear from Windows Media Player 11.

    Original title: my songs seem to disappear from windows media player 11

    I make a playlist and some of the songs come with a "cannot find this file" dialog box I click on 'place to open the file' and the song is there but will not play. Help, I'm losing songs at an alarming rate.

    Hi Akledge,

    1. this happens only for songs with a specific file format?

    2. What is the full error message that you receive?

    3. have you made a recent software or hardware changes to the system?

    Method 1:

    You can try to start the Windows Media Player (WMP) Fixit from link and check if it helps:

    Solve the problems of Windows Media Player video and other media or library

    For more information, see the article:

    Error message when you type the name of a file to play with Windows Media Player: "Cannot open file."

    Method 2:

    If the problem persists, you can visit the article to rebuild the WMP library and check if it helps

    You cannot view, add, or delete items in the library of Windows Media Player 11

    Note: Windows Media Player automatically rebuilds the database.

  • I tried to find this scanner for Windows Server 2003 Standard Edition software, but even now, I'm not find software scan. Printer model: HP 3390 Laser jet

    tried to find this scanner for Windows Server 2003 Standard Edition software, but even now, I'm not find software scan.
    Printer model: HP 3390 Laser jet

    I don't want the drivers.  I mean the software.  The drivers you get from the page server 2003 and the software from the page I referenced.   Otherwise, you need to contact HP, as they provide that software, not Microsoft.

    Steve

  • Error message when you try to download Windows Defender: "first remove Microsoft Client Protection." Cannot find this file through the Add/Remove, search, including hidden or Win Explorer.

    Original title: trying to download

    WinXP SP3, Security Scan run and d/ld: error message when you try to download Windows Defender: "first remove Microsoft Client Protection." Cannot find this file through the Add/Remove, search, including hidden or Win Explorer. What to do now would be much appreciated.

    Also have a related problem about MS Maliciouws software removal tool. For download, but read in the KB that: in XP, the vacuum cleaner will remove the malware, but doing so may trigger the File Protection Win with damages to my operating system.  the tool will attempt to repair the damage, but to rehabilitate prior to infection, that I need to insert the CD of Win. As my computer came with Windows preinstalled, I do not have a disk and will not take the risk of damage, that I can't fix. Do I not download or not... ? Another solution... ?  I also fear that this tool could settle into the routine Win Update and need guidance on the prevention of this facility, if possible, or what to do if it cannot be prevented.

    It can have nothing to do with any of the foregoing. " I'm relaying only because it occurred during the same mission of update: had msg of error that Win Firewall has not been set as a default, which reset, but found this hidden file when searching for the Protection of the customer: "Win 32/Hackdef' - it was a config with the extension ini file and was deleted by Scan."

    Thanks a lot for any assistance.

    scate 39

    Hello

    ·         You have Microsoft Security Essentials on your computer?

    If you have windows installed on your computer security essentials, then you will not be able to install Windows defender. Windows Security Essentials has antispyware component installed.

    You get the error because you have installed MS Security Essentials, which has its own function to antimalware. You don't need or want to install Windows Defender, too. Leave MS Security Essentials installed and do not turn it off.

    See also:

    You can turn on or turn on the firewall in Windows XP, please see the link below:

    http://support.Microsoft.com/kb/283673

  • Windows media player: Media player can not find this file. It may have been moved or deleted

    Originl title: Windows media player

    I get this message: Media player cannot find this file.  It may have been moved or deleted.

    any ideas on how I can fix it myself?   Microsoft Help player said diagnosis has no problem.  I added an external hard drive later.

    Thanks for your help

    Steve

    In WMP, please enable the column path, right click on a column heading (for example, title) and selecting choose columns. Then check if the path of the songs continue to point to the correct location.

    If they do not, press F3 in WMP to do appear to add to the library and make sure that the Advanced Options appear. Manually add the location of the music files to the list, and then click OK. Who help me?

  • How can I find this file from Microsoft: HKCR\CLSID\ {1171A62F-05D2-11D1-83FC-00A0C9089C5A}-to REMOVE & CLEAR?

    Can someone HELP Please find this file and delete it? Thank you

    This isn't a file.  There is an entry in the system registry.
    HKCR is short for "HKEY_CLASSES_ROOT".
    To remove this key, you must use 'Regedit' (start-> Run-> 'regedit').
    Editing the registry can be dangerous.  Make sure that your registry database is backed up before making any changes.  For more information, see:

    "Information for advanced users Windows registry"
      <>http://support.Microsoft.com/kb/256986 >

    HTH,
    JW

  • Defragmenter shows that I have a lot of disk space being taken up by a file that cannot be defragmented. I tried disk cleanup. I can't find this file to remove...

    The Defragmenter report is:
    Fragments of files in file size that cannot be defragmented
    32 330 MB \Documents and Settings\Bill & LaVerne\Local Settings\Temp\~PST5291.tmp
    I tried to find this file in order to remove it, but were unsuccessful.  I have the configuration of the computer to make the "hidden files" visible.  I searched all the temporary files by searching *.tmp and deleated all .tmp files that were more than 30 days old.  I searched files with one of the components of the file listed but am not successfulin find the listed file.
    Why can't I find this file?

    Hi Steven,

    I tried the program you recommended "Pagedefrag", but he did not find any fragmented junk files to be fixed.

    However, I had another idea, I went into "the command prompt ", and progress through the file defragmentation report structure was first listed as the path of the fragmented files.  After clicking on "command prompt " in the program lists, I used an old DOS command line: cd (change directory ) (for each step ) and the following file type listed since the path of the defrag report file until I came to the temp indicated as fragmented file.  Then I typed del (space) and then pasted in the name of the file I wanted to delited "~ PST5291.tmp" and you press on [Enter] was deleted, and I was thrilled!

    I delited the file in mode "command prompt " even if windows has not shown that there was!

    Before I tried this, I got windows put in place a restore point in case where my new idea would cause a problem.

    Oh, before I tried this, I also ran again disk cleanup and led also to search all *.tmp files.

    Note: after you remove the ' ~ PST5291.tmp ' file, I ran again the defrag program with several additional fragmented files that cannot be defragmented reported!  When I deleted them... According to the above method, I managed to free up enough disk space change free space of 13% to 34% of free space on the C: drive.
    Quite impressive.
    Can someone explain why windows program (search or windows explorer) cannot 'see' all these files and why 'disk cleanup' could not find and remove?  They took almost 10 GIG of space!

    Thank you
    E-mail address is removed from the privacy *.

Maybe you are looking for