有一张关键字表,有如下字段
art_id
keyword
last_modify
因为一篇文章允许有多个关键字,所以会产生如下情况的数据记录
1 电子商务 2014-4-7
1 b2c 2014-4-7
现在,要对这种情况的数据进行处理,去除重复,合并关键字,合并后的结果如下
1 电子商务|b2c 2014-4-7
现在思路是:1,先创建临时表;
2,把使用group_contcat函数合并行后的结果,插入临时表;
3,清空原表;
4,再把临时表的数据插回原表。
sql语句:1,Create temporary table temp as( select art_id,group_concat(keyword separator '|' ),last_modify from keyword group by art_id);
2,truncate table keyword
3,insert into keyword( art_id,keyword,last_modify) select * from temp