作者:iamlasong
要求:表格的内容需要变更,变更的内容放在一个临时表中,用SQL语句更新正式表中多个字段。
如果更新一个字段,直接用字段名=子查询就可以了,多个字段更新,将字段在括号中并列写出即可,如下:
update tb_jg t
set t.jgfl = ‘sd‘,
( t.zj_code, t.zj_mc) = (select a.zj_code, a.zj_mc
from song_temp a
where a.zj_code = t.zj_code)
where exists (select 1 from song_temp a where a.zj_code = t.zj_code)
需求:根据子查询创建表,语句如下:
create table sncn_zd_jg as select * from tb_jg where zdbz=‘1‘ order by city_code,xs_code;
如果表已经存在,下面语句则可插入查询结果:
insert into sncn_zd_jg select * from tb_jg where zdbz=‘1‘ order by city_code,xs_code;