SQL两表关联查询&批量修改字段值
SQL关联查询&修改字段,正确范例如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--批量修改报告单位名称&更新时间
--tt和tp两表关联查询,将符合条件的tt表中的principal字段更新到tp表的ruperson字段
merge into nhis34.t_publicplaces tp
using standard.t_organization tt
on (tt.orgcode = tp.r_orgcode and tp.create_time > '2015-05-07 00:00:00')
when matched then
update
set tp.ruperson = tt.principal, tp.update_time = '2015-05-07 09:12:08';
错误范例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--以下为错误语句
/*update nhis34.t_publicplaces
set ruperson =
(select tt.principal
from nhis34.t_publicplaces tp
left join standard.t_organization tt
on tt.orgcode = tp.r_orgcode
where tp.create_time > '2015-05-07 00:00:00');*/
以上错误范例,会报如下错误:
页:
[1]