日期:2014-05-16  浏览次数:20812 次

在线等大神,求一个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)