to fill the gaps with value of lead and the delay and make average and the gap between earned

Thanks in advance

I have table as below
ID          TYPE     NUM     NAME     BEG_MP     END_MP     VALUE
10001103N     3     1190001     WST     0.000     0.220     
10001103N     3     1190002     WST     0.220     0.440     
10001103N     3     1190003     WST     0.440     0.820     12800
10001103N     3     1190003     WST     0.820     1.180     12800
10001103N     3     1190004     WST     1.180     1.220     
10001103N     3     1190004     WST     1.220     1.300     
10001103N     3     1190005     WST     1.300     1.420     14800
10001103N     3     1190005     WST     1.420     1.550     14800
10001103N     3     1190006     WST     1.550     2.030     
10001103N     3     1190006     WST     2.030     2.660     
10001103N     3     1190007     WST     2.660     2.780     
What I need is to fill the gaps with value of lead and the delay and make average and the gap between the values
ID          TYPE     NUM     NAME     BEG_MP     END_MP     VALUE
10001103N     3     1190001     WST     0.000     0.220     12800 ---> Lag value
10001103N     3     1190002     WST     0.220     0.440     12800 ---> Lag Value
10001103N     3     1190003     WST     0.440     0.820     12800
10001103N     3     1190003     WST     0.820     1.180     12800
10001103N     3     1190004     WST     1.180     1.220     13800 ---> Avg(12800,14800)
10001103N     3     1190004     WST     1.220     1.300     13800 ---> Avg(12800,14800)
10001103N     3     1190005     WST     1.300     1.420     14800
10001103N     3     1190005     WST     1.420     1.550     14800
10001103N     3     1190006     WST     1.550     2.030     14800 ---> Lead Value
10001103N     3     1190006     WST     2.030     2.660     14800 ---> Lead Value
10001103N     3     1190007     WST     2.660     2.780     14800 ---> Lead Value
create table AVG_TABLE
(
  ID     VARCHAR2(20),
  TYPE   NUMBER,
  NUM    NUMBER,
  NAME   VARCHAR2(10),
  VALUE  NUMBER,
  BEG_MP NUMBER(6,3),
  END_MP NUMBER(6,3)
)
;

insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190001, 'WST', null, 0, .22);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190002, 'WST', null, .22, .44);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190003, 'WST', 12800, .44, .82);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190003, 'WST', 12800, .82, 1.18);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190004, 'WST', null, 1.18, 1.22);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190004, 'WST', null, 1.22, 1.3);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190005, 'WST', 14800, 1.3, 1.42);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190005, 'WST', 14800, 1.42, 1.55);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190006, 'WST', null, 1.55, 2.03);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190006, 'WST', null, 2.03, 2.66);
insert into AVG_TABLE (ID, TYPE, NUM, NAME, VALUE, BEG_MP, END_MP)
values ('10001103N', 3, 1190007, 'WST', null, 2.66, 2.78);
commit;

Hello

Use LEAD and LAG when you know exactly how far is the target line (for example, if you know the desired value is on the next row).
If you don't know exactly how far is the target line, then FIRST_VALUE and LAST_VALUE are more likely to be useful.

WITH     got_neighbors     AS
(
     SELECT     avg_table.*
     ,     LAST_VALUE (value IGNORE NULLS) OVER (ORDER BY beg_mp)          AS prev_value
     ,     LAST_VALUE (value IGNORE NULLS) OVER (ORDER BY beg_mp DESC)     AS next_value
     FROM     avg_table
)
SELECT       id, type, num, name, beg_mp, end_mp
,       COALESCE ( value
             , ( NVL (prev_value, next_value)
               + NVL (next_value, prev_value)
               ) / 2
             )     AS value
FROM       got_neighbors
ORDER BY  beg_mp to f
;

Riedelme is correct: LAG LEAD (as well as FIRST_VALUE and LAST_VALUE) can return only the values that are there (or that you give as default values). This means that you can not solve this problem with these functions alone; you need something else (as NVL, above) to provide value when the function does not find it.

Tags: Database

Similar Questions

  • How to fill the space between the four points of the paint method?

    Hello

    I have a graphics application and I want to fill the space between four points by painting method how I can do it.

    can someone help me?

    Try to use Graphics.fillRect which allows to fill using coordinates xy as well as a width and a height.

    If the points are not rectangular, you can try to use Graphics.drawFilledPath.

    http://www.BlackBerry.com/developers/docs/5.0.0api/NET/rim/device/API/UI/graphics.html#FillRect (int, 20int %, 20int %, 20int %)

    http://www.BlackBerry.com/developers/docs/5.0.0api/NET/rim/device/API/UI/graphics.html#drawFilledPat... (int [], 20int [], % 20 byte [] % 20int [] %)

  • How to fill the space between the brush strokes, like you can with a direct trace of paint?

    Hello

    I'm currently under OS X El Captain on my Mac, v. 10.11.1. I use the version of Illustrator 2015.

    I imported a sketch and drawn on a calligraphic brush. (I've created a new for the effects of pulling on my Tablet pressure sensitivity). I assumed that I would be able to use live paint tool to fill in the spaces with the color as you can with a path created from the pen tool. I do not speak only to fill a closed shape, but when the incomplete paths touch. Except when I'll make the paint option, it is up to my strokes applied to regular paths - the pen tool. I used the brush to get the effects, so I really want that stay the same and not be uniform in the thickness of line.

    Basically, is it possible that I can use paint dynamic to fill the white spaces between the lines created with a brush, while keeping the effects of this brush? If I can't use the live paint is there another way I can fill in these spaces as I'm using live paint?

    Thank you very much!

    You will need to develop stories, or duplicate your layer, expand that, make your form of direct painting and delete everything on your new layer, but your new form.

  • What is the difference between earning 8 downgrade from Windows 7 or just install Win 7 on 8 to win?

    I understand that to change my machine to win 8 to Win 7, I can either:

    1. make a "downgrade" or

    2 just install Win 7 on 8 to win.

    Which way is better and why, please?

    Thank you, Brad

    Techinical, the term "downgrade" refers to the use of a Windows OS previous business class instead of the class deals currently available OS that is installed on your computer. So unless your computer came at HP with Windows 8 Pro, you're not really downgrading. If you have a class of consumer computer, your only option is to do a clean install of Windows 7 on Windows 8. No way is best, because there is no difference with regard to the way in which the operating system is installed. The only differnce has to do with the Microsoft license terms.

    Please send Bravo

  • Fill the stage with Action Script

    Hello

    I'm new to flash and Action script. I would like to know how I could fill (instead of copy and paste) the scene with a small button e.g. 10 x 10 px. Let me explain what I'm trying to do here. It's a simple game that includes 4000 buttons, 50 lines of 80 buttons. Each button has States, not available, available and in the process. Visitors come to the page and start clicking, wins the one who has the most clicks.

    So instead of doing this with the painful copy and paste, to give the button a unique id, I was wondering if there is a way to do this with action script, generating 50 lines, 80 buttons per line, and each of them giving an id with j ++ or something.

    Thank you very much and sorry for my English.

    Of course, no problem actually. I would use two pieces of code. The first would be a
    class, which extends MovieClip and attached to your button element in the library.
    Then a little to the loop on the main timeline to attach buttons to the
    step and you're all set.

    For the class:

    class com.yourdomain.Sample extends MovieClip
    {
    var myID:Number;

    function Sample() {}

    public function set id(newID:Number):Void
    {
    myID = newID;
    this.onRelease = function() {}
    trace (this.) MyID);
    }
    }

    }

    Of course, you will need to change the com.yourdomain to your own class path.
    Then just put your clip in the library to export for ActionScript and set
    class: com.yourdomain.Sample

    In the main timeline then write a function createGrid bit as follows:

    function buildGrid (tot, sx, sy, pc, cs, rs) {}
    var startX = sx;
    var currX = startX;
    var startY = sy;
    perCol var = pc;
    var colSpace = cs;
    var rowSpace = rs;
    Use tot + 1 because we are not going to go 1-0 in the loop below
    var total = tot + 1;

    for (var i = 1; i)< total;="">
    Clip var = this.attachMovie ("btn", "btn" I, I + 10, {_x:currX,)
    _y:startY});
    clip.ID = i;
    currX += colSpace;
    If (I % perCol == 0) {}
    startY += rowSpace;
    currX = startX;
    }
    }
    }

    And call it:

    buildGrid (100, 20, 20, 10, 12, 12);

    This will make a grid of 100 occurrences of the element named "btn" (one with)
    your attached class), from 20,20 with 10 per line and 12 pixels
    between the centers... When you click on one any of them they will trace their
    appropriate index 1-100

    HTH

    --
    Dave-
    Developer leader
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.Adobe.com/communities/experts/

  • Need to null values with the values of filling the date before weekend/holidays

    I have a table with a Date column, column Type and rate column.

    The problem is when the weekends and holidays, column Type and rate column are null.

    I need all null values with the values of Type and fill rate before that date is the weekend and public holidays.

    Example:

    I have:

    RATE OF TYPE DATE
    07/01/2010 4510 PM 3.71
    07/01/2010 CETE28 4.59
    07/01/2010 TIIE28 4.95
    07/02/2010 4510 PM 3.82
    07/02/2010 CETE28 4.63
    07/02/2010 TIIE28 5.11
    * NULL NULL 07/03/2010 *.
    * NULL NULL 07/04/2010 *.
    07/05/2010 4510 PM 3.91
    07/05/2010 CETE28 4.74
    07/05/2010 TIIE28 5.25

    Will be:

    RATE OF TYPE DATE
    07/01/2010 4510 PM 3.71
    07/01/2010 CETE28 4.59
    07/01/2010 TIIE28 4.95
    07/02/2010 4510 PM 3.82
    07/02/2010 CETE28 4.63
    07/02/2010 TIIE28 5.11
    * 07/03/2010 4510 PM 3.82*
    * 07/03/2010 CETE28 4.63*
    * 07/03/2010 TIIE28 5.11*
    * 07/04/2010 4510 PM 3.82*
    * 07/04/2010 CETE28 4.63*
    * 07/04/2010 TIIE28 5.11*
    07/05/2010 4510 PM 3.91
    07/05/2010 CETE28 4.74
    07/05/2010 TIIE28 5.25

    What could I do?

    Hello

    You can use the analytic LAST_VALUE function to get the last day of work before each date into your table. It will be the same as the current day for every day of work.
    Do it a self-join to combine each current line (c) with the last day of work (l):

    WITH     got_last_work_day     AS
    (
         SELECT     dt, type, rate
         ,     LAST_VALUE ( CASE
                        WHEN  type  IS NOT NULL
                        THEN  dt
                       END
                       IGNORE NULLS
                      ) OVER (ORDER BY dt)     AS last_work_day
         FROM     table_x
    )
    SELECT       c.dt, l.type, l.rate
    FROM       got_last_work_day     c
    JOIN       got_last_work_day     l  ON       (    c.dt          = l.dt
                             AND  c.type          = l.type
                             )
                           OR     (    c.last_work_day     = l.dt
                             AND  c.type          IS NULL
                             )
    ORDER BY  c.dt
    ,       l.type
    ;
    

    Among other things, I guess that the type is NULL if (and only if) the line represents a holiday or weekend, and that the combination (dt, type) is uniuqe.

  • Cursor to fill a column with an increase in the value

    Hello
    I had the example table EMP (empno, full name, etc). I've added the username column and I need to fill it with values: emp1, emp2, emp3,..., emp1000..., etc. (until it corresponds to all employees)
    Can you please provide an example of code to fill the column?
    Thank you in advance.
    update emp
    set username='emp'||rownum;
    

    Max
    http://oracleitalia.WordPress.com

  • How to fill the gaps with data?

    Hello

    I have data points with a header that contains the ID that I have to report to each row of data.

    I want the ID of the Patient to fill the fields below the rank (where the "Obs" and sequential numbers are) until it reaches the next patient id and then do the same thing again and again until the end.

    Is this possible in a single SQL UPDATE statement?

    Thank you, Daniel

    It's data, it's a column:

    Patient ID = system 1000207 = LVS + ZDV + ddI randomization Date = 26/03/2004
    OBS
    1
    2
    3
    4
    5
    6
    7
    Patient ID = regime 1000751 = LVS + d4T + 3TC randomization Date = 25/02/2004
    OBS
    8
    9
    10
    11
    12
    13
    14
    Patient ID = system 1001379 = LVP + d4T + 3TC randomization Date = 17/03/2004
    OBS
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    etc etc.

    Do you have any column order?

    If not, how you will order the data?

    If you have a column for the classification, the described selection will give you the id of the patient in all lines

    select col1,
           last_value(
              regexp_substr(col1,'Patient ID=([0-9]+)',1,1,null,1) ignore nulls
                    )
            over(order by ord_col) s
    from your_table;
    

    You can then use the MERGER based on the ROWID of update...

    Published by: JAC on May 21, 2013 20:18

  • Obligation to fill the values in table advanced according to the selection of a value in another article of lov (not in the advanced table)

    Hi all

    We work in a custom oaf page subdivision. We have an obligation to fill the values in table advanced based on a value selection in an element of the lov (this LOV is not in the advanced table) .can share you it please me steps or examples of code to achieve this. Waiting for response.

    Kind regards

    I do not understand completely still. What do you mean by "default in the table values must be inserted".

    You can create a dummy VO with the same columns and fix the VO in the advanced table.

    In the normal scenario, when the user clicks on submit button, browse this VO, and copy the values to the validation according to VO and appeal EO. If values gets inserted into the database.

    When the user selects the number of PO, simply run the other VO and fill this dummy VO so that values are available in the advanced table. When you click on send, do not copy these values to the EO based VO, so these lines won't get inserted.

    It work?

    See you soon

    AJ

  • Fill a field with a value only if another field has been filled?

    I'm looking to fill a field with a predetermined only if another field is not empty. I have no idea how to proceed.

    Any help would be appreciated.

    Thank you

    Use this code in the custom calculation of LineRow1 script:

    Event.Value = (this.getField("SourceDescriptionRow1").valueAsString == "")? « » : « 001 » ;

  • I'm getting white gaps between the black contour lines and color fill on laser printer

    I'm getting white gaps between the black contour lines and color fill on laser printer

    You're welcome, Calotypist.

    Illy prefer PostScript because it gives you a reliable/complete (more) reproduction (depending on the version, you can also see (more) complete print failure).

    With a PDF basically tell you the printer where to put the points/tasks. Without it, the printer (pilot) has to figure (some) outside.

    If you can get one for the printer in question, a printer PostScript (emulation) driver will leave you direct printing.

  • Save as not fill not custom metadata value defined by the rule of the world

    I created a global rule to set the default value for the date of creation of custom as the date metadata field current system. This rule works fine for normal recording but when I use check in a similar feature of the AAU, the value created is is filled with metadata value of original content instead of the default value defined by the rule. Is it possible to fill the date of creation as default value defined by the rule even when checking in a similar role.

    Thanks in advance!

    Published by: 906120 on January 5, 2012 04:42

    Similar check-in does not script in the field "use defaultvalue", since it must copy the metadata values. However, you can add the script to the "derived field" as well. Don't use dprDefaultValue but dprDerivedValue =
    This script will be evaluated before the check-in operation and any value contained in the metadata field will be replaced by the value set by the script.

    Kind regards
    Boris

  • Fill Dataforms with values smartlist

    Hi Forum,

    I'm trying to load the values for smartlist. I use 11.1.2. Basically, I want to fill the form with values Smartlist members.
    For example:

    Employee entity Position (Smartlist)
    26061 not exempt of 1475
    26061 not exempt of 1475
    23041 1573 temp
    64021 1813 temp


    Not exempt, Temp corresponds to ID 1.2 respectively to smartlist.

    Label ID
    1 non-exempt
    Temp 2

    How can I specify these members in the State of charge?

    Thank you
    Syed

    This will help you for sure, you will have an idea.
    http://download.Oracle.com/docs/CD/E12825_01/EPM.111/hp_admin/ch05s02s01.html
    http://John-Goodwin.blogspot.com/2009/05/ODI-series-loading-smart-list-data-into.html

    See you soon... !!

  • Fill the shape with the pen tool

    Hello

    This could be a very simple question, but he could not understand...

    I did a first title and I want to draw a shape with the pen tool.

    However the resulting only in the form of line instead of him fill.

    So my question: how to draw a filled shape in Premiere Pro with the tool pen?

    Thanks in advance

    The graphical value Type Bézier filled, who will fill the form.

  • How can I fill the records using the value LOV

    Create a form based on the use of the following output Table EMP

    Create a database block IE control-> Dept No. block


    Create a database block - EMP
    Create a LOV to the Dept not according to the dept table.
    For the current No. Dept. Complete records of the employees

    How can I fill the records using the value LOV?


    Thank you

    Hello

    Create trigger KEY-LISTVAL for control_block.dept_no with code similar to the following:

    IF SHOW_LOV ('LOV_NAME') THEN
            SET_BLOCK_PROPERTY ('EMP_BLOCK', DEFAULT_WHERE, 'DEPT_NO = ' || :CONTROL_BLOCK.DEPT_NO);
         GO_BLOCK ('EMP_BLOCK');
         EXECUTE_QUERY;
    END IF;
    

    Hope this helps

    Best regards

    Arif Khadas

Maybe you are looking for