当前位置:Gxlcms > mysql > 写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增

写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增

时间:2021-07-01 10:21:17 帮助过:46人阅读

http://www.cnblogs.com/tangself/archive/2010/09/29/1838234.html 这位园友有讲过,可以看一下,简单说,对于这个题目,用row_number可以写成这样: -- 园友文章中的写法,这也是微软官方文档里的写法 WITH B AS ( SELECT * ,ROW_NUMBER() OVER ( ORDER BY

http://www.cnblogs.com/tangself/archive/2010/09/29/1838234.html

这位园友有讲过,可以看一下,简单说,对于这个题目,用row_number可以写成这样:

--园友文章中的写法,这也是微软官方文档里的写法
WITH B AS (
SELECT *,ROW_NUMBER() OVER(ORDER BY ID ASC) AS ROW_NUM
FROM A WITH(NOLOCK)
)
SELECT *
FROM B WITH(NOLOCK)
WHERE ROW_NUM BETWEEN 31 AND 40

--我一般这么写
SELECT * FROM (
SELECT *,ROW_NUMBER() OVER(ORDER BY ID ASC) AS ROW_NUM
FROM A WITH(NOLOCK)
) B
WHERE ROW_NUM BETWEEN 31 AND 40

人气教程排行