Mysql将一张表查询到的数据更新到新的表上

我们在做数据修复时经常遇到这种情形,具体怎么做如下:

UPDATE case_query_info
SET statusDate=(SELECT TIME FROM (
SELECT MAX(operateTime) AS TIME, caseId FROM operate_log_info  GROUP BY caseId) 
temp WHERE case_query_info.id=temp.caseId )
WHERE case_query_info.statusDate IS NULL;

上面的语句满足从旧表中取分组数据最大值更新到新表的字段上.

你可能感兴趣的:(mysql)