β

两个sql语句

阿权的书房 16 阅读
从A表选出数据更新A表是不允许的,需要借助中间临时表操作

update table_A set department_id=1425
where user_id IN(
select id from (
select user_id as id from table_B
left join table_A using(m_id)
where l_id=143969
) as tmp
)


联合两个表查询做更新

UPDATE table_A t1 , (
select d_id,count(*) as cnt from table_B
where h_id = 143969
group by d_id
) t2
SET t1.d_cnt = t2.cnt
WHERE t1.d_id = t2.d_id;
作者:阿权的书房
资料收集分享,偶尔晾几张相片,感言生活
原文地址:两个sql语句, 感谢原作者分享。

发表评论