sql server 分页/最近查询

sql server 分页/最近查询 (最近3天,0到500条记录,时间和idd倒序)

SELECT t2.rn, t1.* FROM 
dtcontent AS t1 , 
(
SELECT TOP 500 row_number() OVER (ORDER BY DisplayTime DESC, idd DESC) rn, idd 
FROM dtcontent 
where ClassID IN ('C3863', 'C3869', 'C3870', 'C3876') 
and DATEDIFF(dd,DisplayTime,getdate())<3 and DATEDIFF(dd,DisplayTime,getdate())>= 0
) t2 
WHERE t1.idd = t2.idd AND t2.rn > 0 ORDER BY t2.rn ASC


你可能感兴趣的:(DB/SQL/NoSQL,sql,server,分页,最近天数)