下一行中列的值

时间:2012-12-25 08:28:16

标签: sql-server

FromDate        ToDate        TempDate
2011-05-03      2011-08-02    NULL
2011-06-03      2011-08-02    2011-05-03
2007-09-30      2009-09-30    2011-06-03 

我在SQL Server中有一个表,希望列TempDate具有上一行FromDate的值

1 个答案:

答案 0 :(得分:0)

UPDATE tab SET
    Tempdate = (SELECT Max(FromDate) 
                FROM Tab t2 
                WHERE t2.Fromdate < tab.FromDate )