技术 · 2019 年 11 月 8 日

mysql 列的数据操作

合并2列或n列的数据到一个新的列:
UPDATE table1 SET c_new = CONCAT(c1,c2,c3);

将不同时间的数据重新排列,只取最新时间的数据
例:表table里的数据:id,num,update_date
SELECT id,num FROM table t1 where not exists(select id from table where update_date > t1.update_date and t1.id = id) ORDER BY id;

将table2的一列数据(字段data)插入到table1中:
1、先在table1中插入新的字段new_data
2、update table1 inner join (select data, id from table2)tmp on table1.id=tmp.id set table1.new_data=tmp.data;