table1(pdqj,pdh,dwdm)  table2(pdqj,pdh,kmdm,bz)  主键 pdqj,pdh现在修改table2中的bz字段,条件用table1中的dwdm sqlserver 里可以用两个表的视图
update tableview set bz where dwdm='01'oracle 里只能对表修改
update table2 set bz=1 where  pdqj,pdh in (select pdqj,pdh from tableview where dwdm='01') --上面这句该怎么写,或者怎么变通?

解决方案 »

  1.   

    pdqj,pdh 
    如果是一个主键还好,现在是两个主键,条件里没法写啊
      

  2.   

    两表(多表)关联update -- 被修改值由另一个表运算而来
       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 超过2个值
       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
                     )
      

  3.   

    感谢Petergepeter我用这个方法试一下
      

  4.   

    同意Petergepeter 的方法,一个关联的过程,条件是判定where后面为true就可以了。
      

  5.   

    同一楼上的意见,在update的where字句部分使用exists
    update   table2 t2  set   bz=1   where    exists(select 1 from  table1 t1 where t1.dwdm='01' and t2.pdqj=t1.pdqj and t2.pdh=t1.pdh)