我已经看到几个类似的问题,其中包含在另一个表上按值更新表。
但是,如果 T2 拥有多个具有相同帮助的记录,并且也只更新 T1 中状态 = O 的记录?
T1
aid = 2345|Status = O
aid = 2120|Status = B
T2
aid = 2345|Status=B|Date=23/12/2002
aid = 2345|Status=F|Date=11/05/2002
aid = 2345|Status=G|Date=4/04/2002
aid = 2345|Status=R|Date=12/03/2002
aid = 2120|Status=G|Date=4/04/2012
aid = 2120|Status=R|Date=12/03/2005
例子:
UPDATE T1
SET T1.Status = T2.Status
Where T1.aid = (T2.aid of the record that holds newest date or max date)
AND = T1.Status = 'O'