分析:tb_ac_acctinfo中的acctname目前是没有数据的
tb_ac_custinfo中的custname是有数据的
两张表中都有custid字段
需求:将tb_ac_custinfo和tb_ac_acctinfo 根据custid联系起来,将tb_ac_custinfo中的custname写入到tb_ac_acctinfo表中的acctname中去。
sql语句如下:
update tb_ac_acctinfo a
set a.acctname = (select b.custname from tb_ac_custinfo b where a.custid=b.custid)
where a.custid in (select custid from tb_ac_custinfo)这边需要确保查出来的数据返回只有一个值哦,不然会报返回值不值一个的错误哦。
本文介绍如何通过SQL语句将两个表中的关联数据进行更新。具体操作是将tb_ac_custinfo表中的custname字段值更新到tb_ac_acctinfo表的acctname字段中,两表通过custid字段关联。
1万+

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



