/ 中存储网

MySQL服务器update set **=(select)的使用方法

2014-07-13 16:29:56 来源:中存储网
mysql中,不能直接使用set select的结果,必须使用inner join:
 
update a inner join (select yy from b) c on a.id =b.id  set a.xx = c.yy
 

update a inner join (select ceiling(month(data_time)/3) as season  from a  group by ceiling(month(data_time)/3)) c on a.id =a.id  set a.season = c.season
 
 
update  sta_statistcs as a inner join (select   SUBSTRING_INDEX( result,   ',',   1) as   season from sta_statistcs) c on a.id =a.id  set a.data = c.season
 
mysql 字段分割符
select   SUBSTRING_INDEX( result,   ',' ,   1) from sta_statistcs;