MySQL/UPDATE:修订间差异
来自康健生活
小 Kangkk移动页面Mysql/UPDATE至MySQL/UPDATE,不留重定向 |
|||
| (未显示同一用户的2个中间版本) | |||
| 第3行: | 第3行: | ||
<syntaxhighlight lang="mysql"> | <syntaxhighlight lang="mysql"> | ||
UPDATE `md_history` SET `message` = null;</syntaxhighlight> | UPDATE `md_history` SET `message` = null;</syntaxhighlight> | ||
将搜索结果作为更新值。 | |||
<syntaxhighlight lang="mysql"> | |||
update md_work w set folder_id = ( | |||
select tmp.folder_id | |||
from ( | |||
select team_id, id as folder_id from md_folder f | |||
) tmp | |||
where w.team_id = tmp.team_id | |||
); | |||
</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> | |||