Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011
    Posts
    1

    Unanswered: Sql to update table with last day rank

    Hi,
    I have a table with device, date, website and rank, previous_rank as columns e.g.
    device date website rank previous_rank
    1 20110812 www.xyz.com 1 -
    1 20110812 www.abc.com 1 -

    Now, I want to update this table setting previous day rank in previous_rank column(after we get next days data). But I am not able to get it in one sql shot, please help me with this.

    I am able to write a select query which should select last day rank, but can't figure out how to update it

    select t1.device, t1.website t2.rank from
    web_by_rank t1, web_by_rank t2 where
    t1.date_key = 20110809 and
    t2.date_key = 20110808 and
    t2.website = t1.website and
    t2.device = t1.device



    Regards,
    Abhigyan
    Last edited by abhigyan.agrawal; 08-12-11 at 02:58.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Check the LAG analytic function which provides access to a row at a given physical offset prior to that position.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •