oracle数据库中一张表内容如下:name       count
abc          0
abc          0
abc          5
bcd          0
bcd          0
bcd          0
bcd          10
现在想要把每一个name对应的count都更新为原来的不为0的值,更新后如下:
name       count
abc          5
abc          5
abc          5
bcd          10
bcd          10
bcd          10
bcd          10
这个update语句应该怎么写,最好能一条语句把整张表的所有内容全部更新的,在线等,谢谢各位了。

解决方案 »

  1.   

    update your_table m 
    set count = (select max(count) from your_table s where s.name = m.name);
      

  2.   

    update tablename a set a.count=(select max(b.count) from  tablename  b where b.name=a.name) where exists (select 1 from  tablename  b where b.name=a.name);
      

  3.   

    目的就是要把count字段的内容全都更新一样,还有其它一些字段不一样的,没有关系所以没有列出来。
      

  4.   

    我看上面两个sql语句都是把count更新到一个新表里面了吧,有没有办法在原表上更新啊?
      

  5.   

    update table_name a set count = (select max(count) from table_name b where b.name = b.name);
    commit;
      

  6.   

     oh oops, up is not "b.name = b.name",but "b.name = a.name".