MySQL/UPDATE:修订间差异
来自康健生活
| 第14行: | 第14行: | ||
); | ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
复杂更新 | |||
<syntaxhighlight lang="mysql"> | |||
UPDATE | |||
md_team_user tu | |||
INNER JOIN | |||
( | |||
SELECT | |||
MAX(tmp.create_at) AS create_at, | |||
tmp.team_id, | |||
tmp._user_id | |||
FROM | |||
( | |||
SELECT | |||
thf.team_id AS team_id, | |||
thf.user_id AS user_id, | |||
thf.message -> '$.user' AS _user_id, | |||
thf.create_at AS create_at | |||
FROM | |||
md_team_history thf | |||
WHERE | |||
thf.message -> '$.user' IS NOT NULL | |||
) AS tmp | |||
GROUP BY | |||
tmp.team_id, | |||
tmp._user_id | |||
ORDER BY | |||
tmp.team_id, | |||
tmp._user_id | |||
) as cup | |||
ON | |||
tu.team_id = cup.team_id | |||
AND tu.user_id = cup._user_id | |||
SET | |||
tu.create_at = cup.create_at; | |||
COMMIT;</syntaxhighlight> | |||