UPDATE a SET a.nstuId=b.bStuID FROM TableA a INNER JOIN ( SELECT * FROM ( SELECT a.nTID,a.vcCtor, a.nStuID,isnull(b.nStuID,0) AS bStuID,a.dtCTime FROM Play_Task a LEFT JOIN ( SELECT b.vcOID,c.nStuID FROM mp_er b INNER JOIN T3_DR_Sc ON b.nUID = c.nUID )b ON a.vcCtor = b.vcID WHERE a.nStuID > 0 AND a.nStuID <> b.nStuID )a WHERE bStuID > 0 AND dtCTime > '2018-06-15' AND dtCreateTime < '2018-08-07' ) AS b ON a.nTiD = b.nTiD
update a set nDeviceStatus = 11, vcMemo='', nKickOut = 0 from (select top 1000 * from TableA WHERE a = 'aa' order by dtTime asc)a