data Manipulation query

  • Hi All,

    I am new to this forum and trying to develop my TSQL skills. I have the below  script

    create table test (from_set int );

    insert into test values(10)

    insert into test values(20)

    insert into test values(30)

    insert into test values(40)

    insert into test values(50)

    select * from test ;

    go;

    select from_set,

    from_set*10 as new_var

    from test;

    o/p required -

    I don't know how to get "pre_set" column

    Please find required o/p attached as png

    Attachments:
    You must be logged in to view attached files.
  • You're looking for LAG().

    SELECT from_set
    ,prevVal = LAG(from_set,1) OVER (ORDER BY from_set)
    FROM Test;

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply