关于搜索每天top5的sql语句
万能的csdn大神们,请教你们一个问题:
表A里面有个字段AddDate,整个表已经按AddDate排序
请问一下如何搜索每天的top5数据..
谢谢了
------解决方案--------------------;with tab as(
select *,rid=row_number() over(partition by AddDate order by getdate()) from tb
)select * from tab where rid<=5
------解决方案--------------------
select *
from (
select *,ROW_NUMBER() over(partition by convert(varchar(10),AddDate,120) order by AddDate) rn
from A
)t
where rn<=5