update table_p as p
set p_name = a.name,p_user = a.user_id,p_type = 'P02'
from (
select x.user_id,x.name,x.p_id from table_u x
join table_p y on x.p_id = y.p_id
) as a where p.p_id = a.p_id;ps: 试了好几种写法,感觉这种比较合适
本文介绍了一种使用SQL更新表的方法,通过联接两个表并设置特定条件来完成更新操作。此方法适用于需要根据关联表中的信息进行数据更新的场景。
update table_p as p
set p_name = a.name,p_user = a.user_id,p_type = 'P02'
from (
select x.user_id,x.name,x.p_id from table_u x
join table_p y on x.p_id = y.p_id
) as a where p.p_id = a.p_id;ps: 试了好几种写法,感觉这种比较合适
1430
5万+
1万+
202

被折叠的 条评论
为什么被折叠?
