1.先使用上面SQL将子查询结果拷贝到新的临时表t_a中。
SELECT * into T_A FROM( SELECT ReportIdentity , finding ,
(SELECT TOP 1 finding FROM T_REPORTLOG WHERE T_REPORTLOG.ReportIdentity=T_REPORT.ReportIdentity AND T_REPORTLOG.ReportStatus=1300 ORDER BY ReportTime DESC ) ff
FROM T_REPORT ) a WHERE Finding<>ff
2.再使用update语句对t_a中所有记录进行更新到t_report表中去。
注意:from后面的表名应该是子查询的表名,再left join要更新的表名t_report,否则若写的是要更新的表名t_report,则会导致将t_report表中所有记录都更新掉。
update T_REPORT set t_report.finding = fd.ff from t_a fd left join t_report on t_report.reportidentity = fd.reportidentity