同じテーブルに複数のレコードが存在し、最近のレコードのみが変更されます.

1699 ワード

UPDATE RT_INSURANCEBUY T SET INSURERCODE = '03' WHERE T.FRAMENO = 'LHGCM462242025161' AND T.BUYDATE = ( 
SELECT T2.BUYDATE FROM RT_INSURANCEBUY T1
LEFT JOIN (SELECT MAX(BUYDATE) AS BUYDATE ,FRAMENO FROM RT_INSURANCEBUY GROUP BY FRAMENO) T2 ON T1.FRAMENO = T2.FRAMENO AND T1.BUYDATE = T2.BUYDATE
WHERE T2.FRAMENO = 'LHGCM462242025161')