当前位置: 代码迷 >> Oracle技术 >> 大神,SQL,更新一个几十万的数据
  详细解决方案

大神,SQL,更新一个几十万的数据

热度:19   发布时间:2016-04-24 08:13:50.0
在线等大神,求一个SQL,更新一个几十万的数据。
如表tabl1
 a1        a2        a3(用户)      
 77       123        01
 99       233        01
 99       233        01
 88       342        01
 88       342        01
```       ```       ```
 77       31         02 
 99       233        02
 99       233        02
 88       342        02
 88       342        02

修改为:
 a1        a2        a3(用户)      
 77       123        01
 99       123        01
 99       123        01
 88       123        01
 88       123        01
```       ```       ```
 77       31        02 
 99       31        02
 99       31        02
 88       31        02
 88       31        02
 
在oracle数据库下,写一个update语句,把a3相同的,且a1为77的a2字段覆盖到a2为99,88的a2字段。

在线等大神 oracle

------解决方案--------------------

update tabl1 t1
set a2 = (select a2 from table1 t2 where t2.a3 = t1.a3 and t2.a1 = 77)


------解决方案--------------------
update table1 t set t.a2 = (
select s.a2 from table1 s where s.a3 = t.a3 and s.a1 = 77
) where t.a1 in (98,99)
------解决方案--------------------
 merge into t
 using (select a2, a3 from t where a1 = 77) t1
 on (t.a3 = t1.a3 and t.a1 in(99, 88))
 when matched then
   update set t.a2 = t1.a2;
  相关解决方案