三个表的结构简化为上图,现在需要将t_customer表的pname字段全部更新为t_person表的pname对应值。
我用基本的SQL(update与select)语句并没有实现,如果有哪位仁兄能写出来,请回复,谢谢。
经过处理转化,最后的实现是先建立t_user和t_person的VIEW,再根据VIEW进行简单的update就可以了。实现的SQL语句如下:
create view v_personuser AS select tp.pname,tu.uid from t_person tp,t_user tu where tu.pid=tp.pid;
update t_customer tc set tc.pname=(select v.pname from v_personuser v where v.uid=tc.uid);