# update select 语句(注意:必须使用inner join)
# 语法 update a inner join (select yy from b) c on a.id =c.id set a.xx = c.yy
#SELECT knowledge_id,COUNT(0) nums FROM pro_base_timu_knowledge GROUP BY knowledge_id;
UPDATE pro_base_knowledge
INNER JOIN ( SELECT knowledge_id, COUNT( 0 ) nums FROM pro_base_timu_knowledge GROUP BY knowledge_id ) b ON pro_base_knowledge.id = b.knowledge_id
SET pro_base_knowledge.timu_num = b.nums
UPDATE hn_account
INNER JOIN ( SELECT id, contact FROM hn_user_common) AS b ON hn_account.user_id = b.id
SET hn_account.user_name = b.contact WHERE ISNULL(hn_account.user_name)
UPDATE account
INNER JOIN ( SELECT id, contact FROM common) AS b ON account.user_id = b.id
SET account.user_name = b.contact WHERE ISNULL(account.user_name)
MYSQL 根据查询结果批量修改数据
最新推荐文章于 2024-07-21 03:11:30 发布