欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[MySQL]mysql update select 从查询结果中更新数据

程序员文章站 2022-05-24 21:08:15
...

参考自:https://blog.csdn.net/qq_39840681/article/details/79401795

https://blog.csdn.net/qq_36823916/article/details/79403696

 

# 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 A inner join(select id,name from B) c on A.id = c.id set A.name = c.name;

  

相关标签: update