(1)基本语句
update poleinfotable set pressuregrade= ‘001’where circuitname='捷运';
(2)两表关联
update customers a -- 使用别名 set customer_type='01' --01 为vip,00为普通 where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id )
(3)两表关联,但更新字段需要从另一个表计算出来
方法一:
update poleinfotable a set a.pressuregrade= (select pressuregrade from circuitryinfotable b where a.circuitryname= b.circuitryname) where a.pressuregrade is null;
方法二:
update customers a -- 使用别名 set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id) where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id )
------更新二个值------
update customers a -- 使用别名 set (city_name,customer_type)=(select b.city_name,b.customer_type from tmp_cust_city b where b.customer_id=a.customer_id) where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id )
注:更新数据小于1万条的时候用以上方法,超过一万条的话建议还是用游标比较好~