日期:2014-05-19  浏览次数:20444 次

查重并删除点击数比较少的文章
--这条语句是是查询208这个分类(同时包含它的子类)的所有文章里面标题重复的,并找出最大的点击数,和重复的个数的语句。
select   title,maxhits=max(hits),num=count(1)   from   article   where   classid   in   (select   classid   from   f_news_ClassTree(208))   group   by   title   order   by   num   desc

我现在想写一条语句删除其中有重复的,而且点击数不是最大的那些记录。

比如:
“微软倒闭了”这条新闻有3条,那么删掉点击数低的两条,保留点击数(hits)大的那条。

请问如何写这个删除语句。

------解决方案--------------------
delete from article where classid in
(
select classid from article group by classid having(count(classid))> 1
)
and
classid not in(select max(classid) from article group by classid)
------解决方案--------------------
delete from article a where no exists (
select 1 from ( select title, max(hits) hits from article b group by title ) c
where a.hits =c.hits and a.titile = c.title )

最好弄个临时表把 c表 存起来
------解决方案--------------------
delete from article where classid not in(
select article.classid from article ,
(select title,max(hits) hits from article group by title)mhits
where article.title=mhits.title and article.hits=mhits.hits)