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
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
后面我也是类似你的这种方案实现的,楼上几位兄弟的方案估计会更新多次: 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
where b.name is null and a.id<> b.id
set a.name=b.n
where a.name is null
and a.pid=b.pid
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