日期:2014-05-18 浏览次数:20474 次
--如果不需要按照title分组求count --查询前20天内顶数最高的20篇内容,倒序排列 select top 20 title , [count] from tb where datediff(dd,addtime,getdate()) <= 20 order by [count] desc --查询前20天内顶数最高的3篇内容,倒序排列 select top 3 title , [count] from tb where datediff(dd,addtime,getdate()) <= 20 order by [count] desc
------解决方案--------------------
select max(id) as id,CONVERT(varchar(10),[addtime],120)as [addtime], sum([count]) as [count] from [tbl] where datediff(dd,[addtime],GETDATE())<=20 group by CONVERT(varchar(10),[addtime],120) order by [count] desc