mysql 把一张表的某列,更新到另外一张表
由于第二张表的列出来的是集合,但是我们只需要集合的第一条记录
1、先把需要的列和对应关系导到另外临时表中
create table tmp1 as
select a.SCWXDID,a.wxff from wz_scwxd_sub a;
2、由于有重复的,或者集合数据,因此,加上序号
create table tmp2 as (
select (@i:=@i+1) as i,tmp1.* from tmp1,(select @i:=0) as it );
3、依据条件scwxdid,取相同的第一条数据
create table tmp3 as (
SELECT * from tmp2 where i in(
select i from ( select i from tmp2 b GROUP BY b.scwxdid )e
));
4、更新表数据
update wz_scwxd
INNER JOIN tmp3 on wz_scwxd.scwxdid = tmp3.scwxdid
set wz_scwxd.wxff = tmp3.WXFF;