从 t2表中 select 出来数据 ,更新 t1 表里面的数据。
update t1
set
t1.count = (
select max(num) from t2 where t1.id = t2.pid group by pid
)
update t1 set t1.count = (select max(num) from t2 where t1.id = t2.pid group by pid )
在用来更新一些 统计数据方面很有用。
还有
insert into with select insert into myDestTable (userid, name, value, othercolumns) select us.userid, us.name,'myvaluefromcode', othercolumns from users us where us.name = 'mynamefromcode'
来自:Mysql的语句:用select来update