SQLServer的限制和偏移量等效吗?在PostgreSQL中,Limit和Offset关键字,这将允许非常容易分页的结果集。SQLServer的等效语法是什么?
3 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
LIMIT
SET ROWCOUNT
;WITH Results_CTE AS( SELECT Col1, Col2, ..., ROW_NUMBER() OVER (ORDER BY SortCol1, SortCol2, ...) AS RowNum FROM Table WHERE <whatever>)SELECT *FROM Results_CTEWHERE RowNum >= @OffsetAND RowNum < @Offset + @Limit
注:@Offset
holdtom
TA贡献1805条经验 获得超10个赞
select top {LIMIT HERE} * from ( select *, ROW_NUMBER() over (order by {ORDER FIELD}) as r_n_n from {YOUR TABLES} where {OTHER OPTIONAL FILTERS}) xx where r_n_n >={OFFSET HERE}
注:ROW_NUMBER()
添加回答
举报
0/150
提交
取消