I want to update all the rows after the first row for each Team

前端 未结 2 912
野的像风
野的像风 2021-01-17 04:24

I want to update all the rows after the first row for each Team.

TableName: Test

ID , Team , StartTime, EndTime, TotalTime
1.......          


        
2条回答
  •  迷失自我
    2021-01-17 05:07

    You can use a CTE with row_number():

    with toupdate as (
          select t.*, row_number() over (partition by team order by id) as seqnum
          from test
         )
    update toupdate
        set StartDate = DateAdd(SECOND, - ProjectedTime * 60, EndDate)
        where seqnum > 1; 
    

提交回复
热议问题