上图数据:SNum为”18004XXXXX000001K2GW 4000 L1C“,OffLineStation为“OP1010”的有两条数据,当where条件中为上述两者时会同时更新这两条数据,并不是我想要的。
更新要求:在上述条件下更新最新的一条记录
update RM_RepairOffLine set Result = '2',OnLineStation = 'OP1010' where SNum = '18004XXXXX000001K2GW 4000 L1C' and OffLineStation = 'OP1010' and Id = (select top 1 Id from RM_RepairOffLine where SNum = '18004XXXXX000001K2GW 4000 L1C' and OffLineStation = 'OP1010' order by CreationTime desc)
如图:SNum为”18004XXXXX000001K2GW 4000 L1C“,OffLineStation为“OP1010”,时间为“2018-01-05 11:04:36.877”的记录更新了,且只更新了一条哦。