代码:
/****建立临时表,结构与phome_ecms_news相同字段,主键为title****/ create table phome_ecms_news_tmp (id int(11) NOT NULL , classid smallint(6) NOT NULL, onclick int(11) NOT NULL, newspath varchar(50) NOT NULL, keyboard varchar(255) NOT NULL, keyid varchar(255) NOT NULL, userid int(11) NOT NULL, username varchar(30) NOT NULL, ztid text NOT NULL, checked tinyint(1) NOT NULL, istop tinyint(4) NOT NULL, truetime int(11) NOT NULL, ismember tinyint(1) NOT NULL, dokey tinyint(1) NOT NULL, userfen int(11) NOT NULL, isgood tinyint(1) NOT NULL, titlecolor varchar(10) NOT NULL, titlefont varchar(255) NOT NULL, titleurl varchar(200) NOT NULL, filename varchar(60) NOT NULL, filenameqz varchar(28) NOT NULL, fh tinyint(1) NOT NULL, groupid smallint(6) NOT NULL, newstempid smallint(6) NOT NULL, plnum int(11) NOT NULL, firsttitle tinyint(1) NOT NULL, checkuser text NOT NULL, docheckuser text NOT NULL, viewcheckuser text NOT NULL, returncheck tinyint(1) NOT NULL, notdocheckuser text NOT NULL, totaldown int(11) NOT NULL, title varchar(200) NOT NULL, newstime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, titlepic varchar(200) NOT NULL, wplay tinyint(1) NOT NULL, ftitle varchar(200) NOT NULL, smalltext text NOT NULL, writer varchar(30) NOT NULL, befrom varchar(60) NOT NULL, newstext mediumtext NOT NULL, closepl tinyint(1) NOT NULL, havehtml tinyint(1) NOT NULL, PRIMARY KEY (title), KEY classid (classid));
代码:
/****将标题重复的数据倒入临时表****/ insert ignore into phome_ecms_news_tmp select distinct * from phome_ecms_news group by title having count(*)>1; /****将原表标题重复的条目重命名为特殊字段****/ update phome_ecms_news as t1,phome_ecms_news_tmp as t2 set t1.title ='[1234567890}' where t1.title=t2.title; /****删除原表内标题为特殊字段的条目****/ delete from phome_ecms_news where title='[1234567890}'; /****将临时表条目倒回****/ insert ignore into phome_ecms_news select distinct * from phome_ecms_news_tmp; /****清空临时表(可选)****/ truncate phome_ecms_news_tmp;









整理标题重复数据的sql语句[终极优化版]







平板模式