读书人

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

发布时间: 2013-11-13 14:04:18 作者: rapoo

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

读书人网 >oracle

热点推荐