update tb1 a inner join tb1  b on a.pid = b.pid set b.name = a.name
where b.name is null  and a.aid<> b.id

解决方案 »

  1.   

    update tb1 a inner join tb1  b on a.pid = b.pid set b.name = a.name
    where b.name is null  and a.id<> b.id
      

  2.   

    update tb1 a , (select pid,name from tb1 where name is not null group by pid) b
    set a.name=b.n
    where a.name is null
    and a.pid=b.pid
      

  3.   

    后面我也是类似你的这种方案实现的,楼上几位兄弟的方案估计会更新多次:
    update tb1 a , (select pid,max(name) from tb1 where name is not null group by pid) b
    set a.name=b.n
    where a.name is null
    and a.pid=b.pid