Find the last valid value in a date range

The data I work with represents readings from different instruments. A follow-up field of a sum running while this number continues to increase. I need to look at the data for a particular date, but the problem is that sometimes the instrument is turned off. In this case there is no data for that date, however since all I want is the total sum for the signal on this instrument, I need to keep going until I find the latest valid data in the database that would represent the sum up to this point. How can I design a query or procedure that would deal with this eventuality? Some examples of data:
PV_ID                  SMPL_DTE                  INTEG_SINCE_VAL 
---------------------- ------------------------- --------------- 
271                    20-JUL-08 12.05.00 AM     6172.0387459767 
271                    20-JUL-08 12.06.00 AM     6172.0387459767 
271                    21-JUL-08 12.05.00 AM     6172.0387459767 
271                    21-JUL-08 12.06.00 AM     6172.0387459767 
271                    21-JUL-08 08.43.00 AM     6172.0387459767 
271                    21-JUL-08 08.45.00 AM     6172.0387459767 
271                    22-JUL-08 12.05.00 AM     6172.0387459767 
271                    12-AUG-08 04.45.00 PM     6172.0387459767 
271                    12-AUG-08 04.50.00 PM     6172.038748687284 
So, if for example I run a query for July 30, I would need to get the result of the July 22 because it is the last valid number. PV_ID represents the ID of the instrument and the INTEG_SINCE_VAL of the total cumulative for signal readings on this instrument.

Published by: Solerous on March 16, 2009 07:23

Published by: Solerous on March 16, 2009 07:25

Hello

If you want the last row or before a given date of the target as on July 30, 2008)?

Here's a way

SELECT  *
FROM    (
        SELECT    *       -- or whatever columns you want
        FROM      table_x
        WHERE     sample_dte < TO_DATE (:target_dte, 'DD-MON-RR') + 1     -- See note below
        ORDER BY  sample_dte DESC
        )
WHERE   ROWNUM = 1;

NOTE: the above query adds a day to the current deadline, but selects the lines that are less important (not equal to) that link, so if you enter 30 July 08, it compares against 31 July 08, so he would choose anything on the date target itself, no matter what time. In other words, if you ask 30 July 08, you could get something later than 30 July 08 23:59:59, but you wouldn't get 31 July 08 12:00:00 AM.

Tags: Database

Similar Questions

  • 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

  • How to find the last update date, time and user of the file field peoplecode

    How to find the last updated date time fields of peoplecode records?

    Thank you.

    We can check the update date-time using the following query

    SELECT LASTUPDDTTM IN THE PSPCMPROG WHERE OBJECTVALUE1 LIKE "RECNAME" AND OBJECTVALUE2 AS "FIELDNAME".

  • 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;
    
  • Help with the query to return the last possible value

    Can someone please help me to create a query for the situation below?

    Table: TABLEA
    Columns:
    FACID VARCHAR2 (10),
    DEPTID VARCHAR2 (10),
    CHARGENUMBER NUMBER (10)

    I have the following data:

    A, B, 1
    A, B, 2
    C, D, 3
    C, D, 4

    I will return the following:

    A, B, 2
    C, D, 4

    In other words, I would return the last possible CHARGENUMBER for FACID and DEPTID.
    The table has no index, and it is responsible for a worksheet in that order.

    Thank you very much!

    Hello

    If you have a TIMESTAMP column, called entry_dt, you can use a Top - N query like this to find the last x entries.

    WITH  got_rnum  AS
    (
         SELECT  my_table.*
         ,     RANK () OVER (ORDER BY entry_dt DESC)     AS rnum
         FROM     my_table
    )
    SELECT     *     -- or list all columns except rnum
    FROM     got_rnum
    WHERE     rnum     <= x
    ;
    

    It is very common to have a trigger to ensure that columns like entry_dt are met.

    If you have only one statement that inserts with hundreds of lines, they can all have the same entry_dt. (The value of SYSTIMESTAMP is constant throughout a statement, even if it takes a few seconds).
    The above query uses RANK, so if you tell him you want the last 10 entries, it can return more than 10, because it includes all lines with exactly the same entry_dt as the 10th. If you want to exactly 10 rows returned, even if there is a tie for 10th place, then use ROW_NUMBER instead of RANK; the rest of the query is the same.

  • How do the average of the last 5 values of a column as new values automatically entered?

    If the issue is not clear for you, here's a site I found that teaches you how do it on excel. ml https://www.extendoffice.com/documents/Excel/2533-Excel-average-last-5-values.HT    I can't find the corresponding method on the good numbers. Thank you for your response in advance :-)

    Hi Z_J,

    This number approach pulls the last 5 (low) values of table 1 in another table where the average can be calculated.

    Step 1. Add line numbers in column A of table 1. This gives a way for table 1-1 to extract the last 5 values.

    Formula in A2 (and fill down

    = ROW()

    Step 2.

    In table 1-1, the formula in A6 estimated the maximum line in table 1

    = MAX (Table 1::A)

    The formula in A5 (and filling up)

    = A6−1

    Formula in B2 of table 1-1 (and fill down) using VLOOKUP to find a match for each line number in table 1-1 and get the value out of this line in table 1.

    = VLOOKUP(A2,Table 1::A:B,2,FALSE)

    Step 3.

    Now add another row (and insert a new value) to the lower part of table 1

    Lines 3 to 7 are now drawn.

    Ranger by hiding some columns

    Kind regards

    Ian.

  • How to find the last pasted paragraphs FMP?

    I'm sticking FMP several objects at once in a file (a file of changes to the sections containing the changebars) in the main text flow. I want a separator line to go at the end of each pasted section, so I try to insert one after the paste operation. But instead of a line between each section, all lines are added at the end of the file, after all the sections. So if there are 3 glued sections at the end of the file are three lines. My code is below, do you know how I could fix this?

    Thank you, Mark

    function copyPasteChanges (doc, chgRange) {}

    Select the section with changebar and copy it.

    doc. TextSelection = chgRange;

    doc. Copy();

    Prepare for the changes doc and paste there the modified section.

    var firstChgPgf = changesDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf;

    var changesTloc = new TextLoc (firstChgPgf, Constants.FV_OBJ_END_OFFSET);

    var changesTRange = new TextRange (changesTloc, changesTloc);

    changesDoc.TextSelection = changesTRange;

    changesDoc.Paste ();

    To go at the end of the file again (I think)

    var lastPgf = changesDoc.MainFlowInDoc.FirstTextFrameInFlow.LastPgf;

    var dividerPgf = changesDoc.NewSeriesPgf (lastPgf);

    var TLoc = new TextLoc (dividerPgf, 0);

    changesDoc.AddText (TLoc, '_');

    }

    Hi Mark,

    The problem is that the dough does not occur when you think. The dividing line is added at the end of the file, but are not your actions of dough. Actually, I think that maybe a little random where pasta is produced, because this line:

    var changesTloc = new TextLoc (firstChgPgf, Constants.FV_OBJ_END_OFFSET);

    .. .is does not create a valid text location. You can check this by abandoning the service after:

    changesDoc.TextSelection = changesTRange;

    .. and look at where's the insertion point. It will probably be everywhere where you left it last, because the call is not valid. I can't tell you exactly why, except that it has something to do with the fact that you are using the last paragraph in the stream. There is something weird to try to define a range of full-paragraph text with the last paragraph. I'm sure it's related to how the last TFP in a stream does not show a mark of FMP, but beyond that, I don't know how to do what you're trying to do with the last paragraph.

    Having no knowledge of how do it right, any time I need to do this, I create a paragraph "dummy" at the end of the flow to fill that space strange 'last FMP", then do the work around it. In the end, I just want to remove fake TFP. I don't know if it's a good idea or not, but it's the only way I ever get it to work and it sorts the mirror how you could do this manually in the GUI.

    With this, I modified your script as follows, and it seems to work better. Note that I also modified the logic of how to find the last paragraph of the flow by writing a separate function. Your call to the 'FirstTextFrameInFlow' is OK, unless your doc begins to span several pages and/or begins with several empty pages. The function I wrote ensures that you really the last TFP in the stream.

    I hope this helps.

    Russ

    function copyPasteChanges (doc, chgRange) {}

    Select the section with changebar and copy it.

    doc. TextSelection = chgRange;

    doc. Copy();

    Prepare for the changes doc and paste there the modified section.

    var lastPgf = getLastPgf (changesDoc);

    var dummyPgf = changesDoc.NewSeriesPgf (lastPgf);

    var changesTloc = new TextLoc (dummyPgf, 0);

    var changesTRange = new TextRange (changesTloc, changesTloc);

    changesDoc.TextSelection = changesTRange;

    changesDoc.Paste ();

    To go at the end of the file again (I think)

    Don't forget that last TFP is now fake TFP

    lastPgf = getLastPgf (changesDoc);

    var dividerPgf = changesDoc.NewSeriesPgf (lastPgf.PrevPgfInFlow);

    var TLoc = new TextLoc (dividerPgf, 0);

    changesDoc.AddText (TLoc, '_');

    dummyPgf.Delete ();

    }

    function getLastPgf (doc)

    {

    textFrame var is doc. MainFlowInDoc.LastTextFrameInFlow;

    var lastPgf = textFrame.LastPgf;

    While (! lastPgf.ObjectValid () & textFrame.ObjectValid ())

    {

    textFrame = textFrame.PrevTextFrameInFlow;

    lastPgf = textFrame.LastPgf;

    }

    Return lastPgf;

    }

  • My iPhone is dead and the lack of how find the last location?

    How to find the last location of the iphone

    Apple has sent sms on my phone number. We found your lost iphone please refer to the specific location. Apple. messageios.com apple support. What shoud I do

  • How do you find the last time that an address older Windows Live Hotmail has been used if you don't remember the password?

    How do you find the last time an old hotmail address was used... especially if you can't remember the exact password?

    original title: old hotmail address

    How do you find the last time an old hotmail address was used... especially if you can't remember the exact password?

    Good enough if you can't on the account and you can't prove it is yours in order to regain access (via password self-service reset, etc)-then you won't know anything about the account.

  • Camera: Find the last image?

    Hello

    Are there examples of how to find the last image taken after invoking the camera?

    Thank you

    Hi and welcome to the forums!

    If you take the picture and save, and can't find it? Or you take pictures

    Return to the back and you want to know where they are stored as you pull?

    Go to the media and click the photos, as soon as the images are displayed

    Highlight it, click menu, properties. It will show you, device, media and file

    and size.

    You can set the previous directory. Unit > menu button > options.

    Here you can set options for the camera with flash, color, size, and storage in the

    media folders,

    Thank you

    Bifocals

  • [JS] To find the last updated the story?

    Hello.

    I can find the last story added.  (app.activeDocument.stories.lastItem ())

    But I want to find the last updated the story.

    Is there a way?

    Hello..

    Updated the story means that it is many possibilities... for example, if you add a cahracter, deletion of a character, track changes, change of font etc...

    so every change attribute will give the last updated the story...

    I hope that you should check the possibilities!

  • Find the last characters with grep

    I'm lousy with grep and didn't find the solution with google, we will so ask here (help me, please...)

    I need to find the last 7 characters in a paragraph and assign a character style "not break". I know that all the rest, but what is the string to find the last 7 characters (white space included, numbers and letters).

    Thanks in advance.

    try searching. {7} $

  • To find the months and days between 2 dates

    Hello

    I want to find the months and days between 2 dates.

    For example.

    1 - Date: August 25, 2013

    2 - Date: October 23, 2013

    If we consider each month 30 days, it should give

    August 25, 2013 to August 30, 2013 = 6 days

    01-Sep-2013-30-Sep-2013 = 1 month

    October 23, 2013 to October 30, 2013 = 8 days

    Total = 1 month and 14 days.

    Kindly help as soon as possible.

    Thanks and greetings

    Suresh

    Assuming that d2 > d1,.

    where d)

    Select sysdate d1, sysdate + 56 double d2

    Union all select to_date (March 1, 2013 ',' dd-mon-yyyy "") d1, to_date (March 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (5 February 2013 ',' dd-mon-yyyy ') d1, to_date (March 31, 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (February 25, 2013 ',' dd-mon-yyyy "") d1, to_date (March 23, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (February 25, 2013 ',' dd-mon-yyyy ') d1, to_date (March 31, 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (August 2, 2013 ',' dd-mon-yyyy "") d1, to_date (29 October 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (February 1, 2013 ',' dd-mon-yyyy "") d1, to_date (May 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (25 August 2013 ',' dd-mon-yyyy "") d1, to_date ('03-Sep-2013', 'Mon-dd-yyyy') d2 double

    Union all select to_date (July 30, 2013 ',' dd-mon-yyyy "") d1, to_date (August 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (July 31, 2013 ',' dd-mon-yyyy ') d1, to_date (August 30, 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (July 31, 2013 ',' dd-mon-yyyy ') d1, to_date (3 August 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (3 July 2013 ',' dd-mon-yyyy "") d1, to_date (August 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date ('31-08-2013', ' dd-mm-yyyy'), to_date('05-10-2013','dd-mm-yyyy') of the double

    Union all select to_date ('05-02-2013', ' dd-mm-yyyy'), to_date('31-03-2013','dd-mm-yyyy') of the double

    Union all select to_date ('05-02-2013', ' dd-mm-yyyy'), to_date('05-03-2013','dd-mm-yyyy') of the double

    Union all select to_date ('05-02-2013', ' dd-mm-yyyy'), to_date('05-02-2013','dd-mm-yyyy') of the double

    )

    Select d1, d2,

    1 + 30 * trunc (months_between (d2, d1)) + LESS (extract (day of d2), 30)-LESS (excerpt (d1 day), 30)

    + CASE when extracted (d2 day)< extract(day="" from="" d1)="" then="" 30="" else="" 0="" end ="">

    d

    D1 D2 DAYSBETWEEN

    ----------- ----------- -----------

    October 10, 2013 5 December 2013 56

    March 1, 2013 30 March 31, 2013

    5 February 2013 March 31, 2013 56

    February 25, 2013 March 23, 2013 29

    February 25, 2013 March 31, 2013 36

    August 2, 2013 29 October 2013 88

    February 1, 2013 may 31, 2013 120

    August 25, 2013 03 - Sep-2013 9

    July 30, 2013 31 August 31, 2013

    July 31, 2013 August 30, 2013 31

    July 31, 2013 3 August 2013 4

    July 3, 2013 August 31, 2013 58

    31 August 2013 5 October 2013 36

    5 February 2013 March 31, 2013 56

    5 February 2013 March 5, 2013 31

    February 5, 2013 February 5, 2013 1

    In my view, which corresponds to your rules.

  • How can I find the last selection OR has highlighted it selection?

    When I select some elements in indesign I have the option of 'command + click' to highlight one selections. How can I find this item highlighted in the script?

    OR

    How I'll get the last item selected in indesign.


    I'm writing a script that relies on certain properties of the element highlight or the last selected item.


    Thank you


    Screen Shot 2014-08-01 at 12.17.03 PM.png

    Thank you myDavey. It's not exactly what I was looking for, but he had good information on something else, I'm trying.

    I found the solution to my problem. This highlighted selection apparently called the object 'key '.

    And it can be used in the script as app.selectionKeyObject. This solves what I was looking for.

    And you can find the last selection by selecting the last item in the selection table.

  • display the last 25 values in lov

    Hi How can I don't post that the last 25 values in my lov am in jdeveloper 11.1.1.6.0
    My iterator is
    <iterator Binds="CountryLOV1" RangeSize="-1"
                  DataControl="UAMAppModuleDataControl1" id="CountryLOV1Iterator"/>

    I guess you must write the request in a way that it returns the line that you want to see (the last n in your case).

    Timo

Maybe you are looking for

  • Sandbox

    Guys all standard safety measures on the iMac, for example; integrated security as Xprotect, Gate Keeper, firewall, browser security measures for example: Sandboxing, I'm sure that people like me would be interested to learn how it works?

  • HP pavilion windows 7 laptop. : low HP Tools [E] disk space.

    Hello every time I open a program in my computer this message which tells me that my disk space on the drive tools Hp [E] runs. I tried to disable the security settings of the system but drive E is not listed in there, and then there was this topic w

  • How to keep stuff on my Clipboard even after registration and closing?

    I'm editing a long document in Word and I have more than a dozen clips on my clipboard that I need to experiment with as to where they're going. When I stopped my computer all the information on the Clipboard are deleted as well. I know that I can op

  • Songs being listed twice or three times

    Why the media player does not duplicate the songs of some of the CD I ripped?  Everything seems fine after extraction, but a day or later, I look at the album and each song is listed twice and even three times.  I have move and delete duplicate songs

  • Problem connecting Wi - Fi networks unsecured with Windows 8

    Hi all! I have problems connecting to unsecure networks that require more authentication via browser thr, as networks of the hotel or Starbucks. The networks work wirh all other devices I have, but on my laptop with Windows 8, it doesn't. I get a "li