------解决方案-------------------- select id,userid,time_s,
datediff(ss,time_s,(select top 1 time_s from 表 where userid=a.userid and id>a.id order by id asc)) dur
from 表 a ------解决方案-------------------- ;with cte as (select id,userid,time_s,
datediff(ss,time_s,(select top 1 time_s from 表 where userid=a.userid and id>a.id order by id asc)) dur
from 表 a)
update 表
set dur=cte.dur
from 表 inner join cte on 表.userid=cte.userid ------解决方案--------------------
update a set a.dur=datediff(mm,a.time_s,(select min(time_s) from tab where time_s>a.time_s and userid=a.userid)) from tab a
------解决方案--------------------
update 表 set dur=datediff(ss,time_s,(select top 1 time_s from 表 where userid=a.userid and id>a.id order by id asc))