update tableset name_id = (select distinct name_id from table t where t.name = table.name and t.name = 1) where flag = 0 --当flag等于0的时候更新--更新的值为:与当前name相同的,并且flag等于1的name_id