如果你表2的数据很多(几百万条),那么建议不要用关联来做,可能会很慢。可以按如下思路来做:
1. 从表2中查询出sum和后写入一个临时表temp(mid,name1,money 共3个字段)
eg:insert into temp(mid,money) select mid,sum(money) as money from 表2 group by mid
2.更新temp表中的name1字段。
eg: update temp A set A.name1=(select B.name1 from 表1 B where A.mid=B.mid)
3.从temp表中的数据即是你要的数据。