比如有一堆数据,要求每种类型数据(每组)中取出前三条。
按照状态Statu分组,查询出这个组中前三条数据。当然这些数据都是在一张表中显示的
select * from dbo.BlogArticleCate as t1 where Id in
select * from dbo.BlogArticleCate as t1 where Id in
(
select top 3 Id from dbo.BlogArticleCate where Statu=t1.Statu order by Addtime
)
同上的题目 这个语句比较好理解
select * from
(select *,rowId=row_number() over(partition by Statu order by Addtime desc ) from dbo.BlogArticleCate
)t
where rowId<=3
这个 partition 是按照什么分割

浙公网安备 33010602011771号