--这条语句是是查询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)大的那条。请问如何写这个删除语句。
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)大的那条。请问如何写这个删除语句。
(
select classid from article group by classid having(count(classid))>1
)
and
classid not in(select max(classid) from article group by classid)
--删除重复的记录,重复的记录中保留编号最大的一个
delete article where articleid not in(select max(articleid) from article group by title)我现在要
--删除重复的记录,重复的记录中保留点击数最大的一个
hits就是点击数字段
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表 存起来
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)