有如下的查询方法:
mysql update set **=(select)
在mysql中,不能直接使用set select的结果,必须使用inner join,例如:
1,
复制代码 代码示例:
update a inner join (select yy from b) c on a.id =b.id set a.xx = c.yy
2,
复制代码 代码示例:
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
3,
复制代码 代码示例:
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;