MySQL/UPDATE:修订间差异
来自康健生活
< MySQL
小 Kangkk移动页面Mysql/UPDATE至MySQL/UPDATE,不留重定向 |
|||
| (未显示同一用户的1个中间版本) | |||
| 第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> | |||
2026年1月19日 (一) 13:42的最新版本
引言
更新值。
UPDATE `md_history` SET `message` = null;
将搜索结果作为更新值。
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
);
复杂更新
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;
No categories