get my head wrapped around the LAG function

Oracle 11.2.0.4 Std Ed

drop table change_hist;

create table change_hist (file_name varchar2 (30),)

date of sample_date,

number of blocks

);

insert into change_hist values (to_date('2015-07-01','yyyy-mm-dd'), 'file1', 5);

insert into change_hist values (to_date('2015-07-02','yyyy-mm-dd'), 'file1', 5);

insert into change_hist values (to_date('2015-07-03','yyyy-mm-dd'), 'file1', 6);

insert into change_hist values (to_date('2015-07-04','yyyy-mm-dd'), 'file1', 6);

insert into change_hist values (to_date('2015-07-05','yyyy-mm-dd'), 'file1', 6);

insert into change_hist values (to_date('2015-07-01','yyyy-mm-dd'), 'file2', 5);

insert into change_hist values (to_date('2015-07-02','yyyy-mm-dd'), 'file2', 5);

insert into change_hist values (to_date('2015-07-03','yyyy-mm-dd'), 'file2', 5);

insert into change_hist values (to_date('2015-07-04','yyyy-mm-dd'), 'file2', 5);

insert into change_hist values (to_date('2015-07-05','yyyy-mm-dd'), 'file2', 5);

insert into change_hist values ('file3', to_date('2015-07-01','yyyy-mm-dd'), 5);

insert into change_hist values ('file3', to_date('2015-07-02','yyyy-mm-dd'), 6);

insert into change_hist values ('file3', to_date('2015-07-03','yyyy-mm-dd'), 6);

insert into change_hist values ('file3', to_date('2015-07-04','yyyy-mm-dd'), 6);

insert into change_hist values ('file3', to_date('2015-07-05','yyyy-mm-dd'), 6);

Desired result

file_name sample_date prev_value curr_value

File1 2015-07-03 5 6

File2 2015-07-02 5 6

My first attempt...

SQL > select file_name,.

2 sample_date,

3 lag (blocks, 1) (order sample_date) as prev_blocks

4 change_hist;

FILE_NAME SAMPLE_DA PREV_BLOCKS

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

July 1, 15 file1

July 1, 15 5 file3

July 1, 15 5 File2

File2 2 July 15 5

File1 2 July 15 5

file3 2 July 15 5

File1 July 3, 15 6

File2 July 3, 15 6

file3 July 3, 15 5

File1 4 July 15 6

file3 4 July 15 6

FILE_NAME SAMPLE_DA PREV_BLOCKS

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

File2 4 July 15 6

File2 July 5 15 5

File1 July 5 15 5

file3 5 July 15 6

15 selected lines.

SQL >

SQL > spo off

  1  select * from (select file_name, sample_date, lag(blocks) over (partition by file_name order by sample_date) prev,
blocks
  2  from change_hist)
  3* where prev != blocks
SQL> /                                                                                                             

FILE_NAME                      SAMPLE_DA      PREV    BLOCKS
------------------------------ --------- ---------- ----------
file1                          03-JUL-15          5          6
file3                          02-JUL-15          5          6                                                    

You know... you need to partition the file name

Edit: in the interest of beat some people with a force equal regardless of their status, you didn't really know we tell how to achieve these results, so I could refer to the FAQ on how to ask a question

Tags: Database

Similar Questions

  • How can I get txt to wrap around the images in CS6

    I used to use a very old version of Dreamweaver (on version 3) and decided to buy me a beautiful new version so I now CS6

    Everything is good except for the fact that I can't find out how to pack the txt around the images that I insert into a paragraph - it used to do this automatically as soon as you set the alignment of the images. Its driving me crazy that I can't get out!  Anyone can shed light on how to do this now please.

    Thank you

    It's called 'float' in the CSS.

    You can see a small tutorial here: http://www.tizag.com/cssT/float.php

  • How can I using an apple extreme get a better signal around the House?

    How can I using an old apple extreme get a better signal around the House?

    I use an old apple express and a new express from apple.

    I need to update my extreme from apple for the last device namely a time capsule.

    Can I use my apple extreme connected to my new camera add more points around the House?

    What is the model number of the old AirPort Extreme?

    What is the model number of the old AirPort Express Terminal?

    We assume that the model number of the new AirPort Express Terminal is A1392, correct?

    What connects to what now on your network?  It looks like this?

    Internet connection > Modem > new AirPort Express?   How the old Express connects to the new Express?   Cable?  Wireless?

  • A text will not wrap around the object. Some does. Anyone?

    I worked in InDesgin (currently the CS6 for Mac) for many years. I'm not an expert, but fairly well-versed and comfortable with the program. I think I know almost everything about the wrapping of text and its options and how it works. But it drives me crazy.

    I have an imported MSWord part of the text. I have an item I want to insert in the text. Normal procedure. Easy. But this text will NOT wrap around the object. What about other texts? Yes. Other text in the document wrap around that object even very well.

    I rebooted the computer and the program. Check the settings as much as I can think and even spruced up the document from scratch as a MS Word document. Yet, no film.

    This happened to someone? What is going on? Help.

    Check the options of text block for the text that will not wrap. Ignore text dresses it is checked?

  • I'm taking a vector object, say a flower, compensate for a path, then get a vector path around the outside edge of the offset.  I take my flower, add a line, compensate for this trait, then select Add to Pathfinder, which gives me visually the exact offse

    I am taking a vector object, say a flower, compensate a path then get a path independent vector around the outside edge of the offset.

    I take my flower, add a line, compensate for this trait, then select Add to Pathfinder, which gives me visually the exact shape of offbeat perimeter I'm looking for.  The problem is that this isn't a vector path in its own right.  Is there a way to get Illustrator to recognize the lag shot as it is vector own way

    Please forgive me if my terminology is off that I am not a formally trained graphic designer.

    MP,

    If I (put) understand it, object > decaying appearance.

    There is a difference between effect > Pathfinder and window > Pathfinder.

  • How to get rid of border around the linked image in IE?

    Still developing my page and I wanted to see what it looks like ona a few different computers.  I've linked the images as part of my bar side/nav bar.  In Firefox on my machine

    the images are as I want them to be... sitting in the border sidebar with no individual border around them.  If I watch on another computer with Firefox

    If I look in IE, each image has its own black border around the image (which I assume is because I put them in place in the form of links).  How can I change the

    code for these borders do not appear in Internet Explorer and it works on any version of Firefox can be implemented?

    http://rickcicciarelli.com/AntiqueTargetThrowers.html

    Try to add this code to your CSS stylesheet:

    #sidebar img {}

    border: 0px;

    }

    Also, FYI, you can move your styles of links in the head of your page to your CSS stylesheet.

    Chris

    www.cdeatherage.NET

  • Grouping and the LAG function

    Oracle 10.2.0.4 SE - One on OL 5 x 86-64

    Trying to write reports on statspack tables. In view of this query
    select     
    --     s1.ucomment
         w1.event
    ,     s1.snap_id
    ,     to_char(s1.snap_time,'dd-Mon-yyyy hh24:mi:ss') snap_time
    ,     lag(w1.total_waits)
    over (order by s1.snap_id) prev_val,
          w1.total_waits - lag(w1.total_waits)
                            over (order by s1.snap_id) delta_val
    ,     lag(w1.time_waited_micro)
    over (order by s1.snap_id) prev_val,
          w1.time_waited_micro - lag(w1.time_waited_micro)
                            over (order by s1.snap_id) delta_val
    from      stats$snapshot s1
    ,     stats$system_event w1
    where s1.snap_id = w1.snap_id
      and w1.event = 'db file sequential read'
    order by w1.event
    ,     s1.snap_id
    ;
    EVENT                                                               SNAP_ID SNAP_TIME              PREV_VAL  DELTA_VAL   PREV_VAL  DELTA_VAL
    ---------------------------------------------------------------- ---------- -------------------- ---------- ---------- ---------- ----------
    db file sequential read                                                   1 25-Apr-2013 11:00:51
    db file sequential read                                                   2 25-Apr-2013 12:00:51     959235      39179  949588625   29088092
    db file sequential read                                                   3 25-Apr-2013 13:00:51     998414      29632  978676717   24938574
    db file sequential read                                                   4 25-Apr-2013 14:00:52    1028046      21547 1003615291   23101379
    
    4 rows selected.
    Works perfectly. But I would like to delete the ' where... w1.event = 'db file sequential read' and get a report on all events. Of course, simply commenting on this condition means that the first occurrence of an event is "shifted" against the last occurrence of the previous event. Can not find a way to get the logic that do break and start the 'delay' all over again.

    You use lag (...) over (partition by the order of the events of snap_id), i.e. "partition by the event" will do lag a ' star on "for each different event

  • Wrap around the text - illustrator CS6

    Hi all

    I guess it's one that is easy if you know how, but I did not.

    I have a picture and I want to wrap the text around it to be a form of heart love similar to this image: http://i1.cpcache.com/product_zoom/23084...

    Is it possible to do so on measure/manual, or is this a case of using the feature bow to varying degrees?

    of course, it's a nice and simple. Draw a path in the shape you want the text to follow, and then select the Type on a path tool and click on the beginning of the road and start typing

  • I get an incorrect value for the MIN function?

    Hello

    I get an incorrect value when I run the query below. Here, I'm getting the minimum of the two values. I use the function table of pipeline. This split function the comma separates into single value string. Actuatlly of the sub query min value is 956.23. But he's back 1002.56 as min value. How is it possible?

    Other wise, is there another way to get the min of comma-separated string value?
    SELECT  MIN(COLUMN_VALUE)
    FROM    TABLE(get_string_comma('956.23,1002.56',','));

    Hello

    I understand your situation, try:

    SELECT  MIN(to_number(COLUMN_VALUE))
    FROM    TABLE(get_string_comma('956.23,1002.56',','));
    

    Kind regards

  • Using the LAG function to find a previous record

    Hey,.

    I tried searching the forum for this, but I didn't actually even know what to look for, so I create a new thread.

    The SQL below displays a list of prices:
    WITH T AS (
      SELECT 1  AS ID, 'PERM' AS TYPE, 100 AS PRICE, SYSDATE + 1 AS START_DATE FROM DUAL UNION
      SELECT 3  AS ID, 'TEMP' AS TYPE, 90  AS PRICE, SYSDATE + 2 AS START_DATE FROM DUAL UNION
      SELECT 7  AS ID, 'TEMP' AS TYPE, 80  AS PRICE, SYSDATE + 3 AS START_DATE FROM DUAL UNION
      SELECT 8  AS ID, 'PERM' AS TYPE, 75  AS PRICE, SYSDATE + 4 AS START_DATE FROM DUAL UNION
      SELECT 16 AS ID, 'TEMP' AS TYPE, 70  AS PRICE, SYSDATE + 5 AS START_DATE FROM DUAL UNION
      SELECT 20 AS ID, 'TEMP' AS TYPE, 60  AS PRICE, SYSDATE + 6 AS START_DATE FROM DUAL UNION
      SELECT 34 AS ID, 'TEMP' AS TYPE, 50  AS PRICE, SYSDATE + 7 AS START_DATE FROM DUAL
    )
      SELECT T.ID
           , T.TYPE
           , T.PRICE
           , TRUNC (T.START_DATE) AS START_DATE
           , CASE 
               WHEN T.TYPE = 'PERM' 
                 THEN T.ID 
                 ELSE LAG (T.ID, 1, NULL) OVER (PARTITION BY NULL ORDER BY T.ID)
             END AS BASE_ID
        FROM T
    ORDER BY T.START_DATE
    The challenge is to produce this output:
    ID TYPE PRICE BASE_ID
     1 PERM   100       1
     3 TEMP    90       1
     7 TEMP    80       1
     8 PERM    75       8
    16 TEMP    70       8
    20 TEMP    60       8
    34 TEMP    50       8
    What I want to achieve is to bring a column with the ID of the most recent prices of TEMP PERM price.
    and it's own ID of prices of PERM.

    My attempt using LAG to browse the set of records, but it uses 1 statically. If there was a way to arrive at a number
    for each TEMP price say to what extent is the most recent Perm, then I could use that number instead of 1.

    Something like:
    ID TYPE PRICE DISTANCE_FROM_PREV_PERM
     1 PERM   100                       0
     3 TEMP    90                       1
     7 TEMP    80                       2
     8 PERM    75                       0
    16 TEMP    70                       1
    20 TEMP    60                       2
    34 TEMP    50                       3
    Any help will be greatly appreciated.

    Thank you.

    Maybe

    select id,type,price,
           last_value(base_id) ignore nulls over (order by the_row) base_id
    /*     last_value(base_id ignore nulls) over (order by the_row) base_id  -- old way */
      from (select id,type,price,start_date,
                   case type when 'PERM' then id end base_id,
                   row_number() over (order by start_date) the_row
              from t
           )
    

    Concerning

    Etbin

  • CS5 - label Wrap around a cylinder (as the label of wine or pop can)

    [This is not a question specific to Windows, I do not exclude this response Mac users, but there is no platform neutral forum here]

    In Photoshop CS3 and earlier, taking a layer, such as a label of a bottle of wine or a jar, wrapping around a cylinder 3D and compositing of a picture (of the real jar or bottle) was almost trivially easy.

    Unfortunately, with the 3D tools made available in CS4 +, the simplicity of the scarf > cylinder option seems to have been lost.

    Wrapping a complex texture around a cylinder (full coverage, up and down) is possible, but what about a packaging label (especially one that has a cut that is to say: not a full coverage)?

    A few quick searches have surprisingly turned up no tutorials on the subject. What was once a simple technique became so technical and obscure?

    Can someone point me to a tutorial (video or written), or provide a list of steps here on this forum?

    Thank you!

    Hello

    Sketch for this exercise is to generate a 3D cylinder, creating illustrations to wrap around the cylinder, duplicate, then modify this work to be used as a mask and then reorganize the 3D on a composite element together.

    Then the basic steps, I used to do this:

    (1) new 1024px x 512px, RGB doc/white background.

    (2) 3D > new mesh from grayscale > cylinder.

    (3) window > 3D. Choose the material 'Background '.

    (4) in the bottom of the 3D Panel, select the texture of contextual opacity and choose 'Remove Texture' (you will add back to step 10).

    (5) in the same box, select texture broadcasts pop up and choose "OpenTexture"... »

    (6) here's where you add the label icon you want to bend around the cylinder. I used a layer style of text layer w/race for this example.

    (7) when you work as you want, layer > duplicate layer to a new file.  This new file will be used for the texture of opacity that masks the area of the label to give you irregular shapes (ie. cut).

    (8) to select all the pixels in the layer and edit them to white, and then on a new layer under black fill. It's your new card of the opacity. Save it in a working directory for use in the next step, and close the file. Also, save and close the file of the work of stage 5/6 (it is stored as a smart object in the original of the stage 1 file)

    (10) back with the original file from step 1 (with the selected 3D layer) in the bottom of the 3D Panel, select the texture of contextual opacity and choose "Load Texture... ». Go to the texture of opacity to step 8 and choose 'open '.

    (11) you should now see just your dress-up work of label in a cylindrical shape. You can use the tool rotation of the 3D camera to visualize the different angles.

    (12) now bring your jar for compositing image. Where is manipulating the 3D layer to align the scale and perspective can get complicated. I try to use the tools of camera 3D for this work (with the object overall scaling an exception). I also use the "Illustration" rendered preset Shaded to help visualize.

    I hope that it becomes to some of your questions. This is a related title of Dr. Brown for CS4 that the interaction of the demos and reinforces aspects of texture mapping: http://tv.adobe.com/watch/the-russell-brown-show/creating-transparent-3d-globe-graphics/

    Kind regards

    Steve

  • by using the LAG() and MIN() functions

    So, I try to get the smallest number in a column of an alias I use LAG() in. I know, which makes no sense, so here's what im trying to do with a SQL statement:

    Select MIN (NUM1 - lag (num1, 1, 0)) over (ORDER BY NUM1) AS J_LAG ORDER BY HEY HEY

    Basically I want the smallest number of the column that I run the lag function on. When I try to it says, ' ORA-30484: lack of specification of the window for this function. I tried to put in brackets the minutes like this: MIN (NUM1 - lag (num1, 1, 0)) and as follows: MIN (NUM1 - lag (num1, 1, 0) over (ORDER BY NUM1)) and none of them does not seem to work.

    Any ideas?

    -Joshua
    like this ??
    
    Select Min(hey) From (Select num1 - lag(num1,1,0) over(ORDER BY NUM1) As hey From J_LAG)
    
  • How to get distinct records by using the ListAgg OBIEE report function?

    Hi all

    I get a correct result as mentioned below. But I don't see duplicates in my result here, in my example, I get duplicate for the name of the employee 'Pat '. So how to get Distinct values by using the LISTAGG function?

    Data set of sample with the Department and its employees

    Service employee

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

    Marketing Michael

    Pat of marketing

    Pat of marketing

    Pat of marketing

    Purchase of Den

    Purchase of Alexander

    Purchase of Shelli

    Purchase of Sigal

    Guy of purchase

    Purchase of Karen

    Using the ListAgg function, we can convert it to:

    Employees of the Department

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

    Marketing of Pat, Pat, Pat, Michael

    Purchase of Sigal, Shelli, Karen, Guy, Den, Alexander

    I tried a lot of things, but I'm not able to understand how exactly this can be achieved, if anyone has any idea or suggestions please do share, thanks in advance.

    After much research, I found the solution & I want to share what he finds very useful, we can create SQL logic in the Advanced tab, as below and after you click Rescan, and then you will get your desired results.

    SELECT saw_0, Evaluate_Aggr T1.dept ("ListAgg(%1,'' & '') intra group (about 1%)") ("as long as VarChar (1000), T1.emp) saw_1 FROM)

    SELECT 'emp_dept '. "the Department dept,

    'emp_dept '. "' employee ' emp

    IN THE "DOMAIN".

    GROUP BY dept, emp

    ) T1 GROUP FROM T1.dept ORDER BY saw_0

    Also note here that we have good anti-aliasing for columns parent (ex: saw_0, saw_1), another by mistake oracle bi server.

  • How can you add code to create the wrapping around an image of the text?

    I have read many responses regarding a text wrapping and padding - but I could not to by adding the code.
    This is one of the pages I work on - Maureen Brouillette: mixed technique: the gallery upstairs
    Thanks for your help!

    Your CSS code already contains classes for floating elements.

    / * ~ ~ various float/clear classes ~ ~ * /.

    .fltrt {/ * This class can be used to float right to the item in your page.} The floating element must precede the element it should be next to the page. */
    float: right;
    left margin: 8px;
    }
    .fltlft {/ * This class can be used to float an element on your page.} The floating element must precede the element it should be next to the page. */
    float: left;
    right margin: 8px;
    }
    .clearfloat {/ * This class can be placed on one}
    or div empty as the final element after the last div floating (in the #container) if the #footer is removed or put out the #container * /.

    Clear: both;
    height: 0;
    font size: 1px;
    line-height: 0px;
    }

    ...

    Your text will wrap around the floating image...

    ...

    Your text will wrap around the floating image...


    Nancy O.

  • Partially the text will wrap around multiple aligned images

    I was floating three images on the right side of my site, but the text will only wrap around the bottom image.

    www.insaneskitrain.com/options

    Not sure that I am! I looked at www.insaneskitrain.com/options.html and pictures down further than the text so I t will not wrap until it passes. Maybe I missed your point.

Maybe you are looking for

  • Why CD - RW are not recognized on my A60 106

    I got an A60-106, had for about 6 months and still I can't recognize cd - rw which is empty media. It just does not, even if the player according to the manual says he should (uj-811 t).Cd - rw discs are fine as I checked in another computer. I have

  • photos of detachment of the problem in tweed

    I can't get my pictures to post properly Tweed. I go through the process of adding the picture to my tweet, once I hit the button send email, it says mail. but it never shows in my tweets, and I get an email from "returned mail". I think I did someth

  • F11 system recovery problem Hp

    Need some advice.I recently got a computer notebook dm3-1035dx of Hp. The hard drive of the laptop is 320 GB Toshiba and its partitioned into1 - 199 MB NTFS system2 C 285 GB NTFS Drive3 - D recovery drive 12.62 GB NTFS4 HP_Tools 103 MB FAT32 I want t

  • Open the email and have a photo and a comment here - how can I get the photo as an attachment

    I want to send a Christmas card from our family with a comment him - but don't want to send it as an attachment - I have receipt of emails that when I open them the picture and the comment are there in the body of the e-mail - DO NOT want to send as

  • Windows Media Center opens but the program closes itself and offers no solution?

    Hello, I have windows vista family premium and Im trying to use my windows media center. I don't use it often, but now Im trying to add the Extender for my xbox 360. The program does not open, but then once I click on what anyone in the program or ju