首頁 >資料庫 >mysql教程 >写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-07 15:34:011683瀏覽

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可以写成这样:

<span>--</span><span>园友文章中的写法,这也是微软官方文档里的写法</span><span><br></span><span>WITH</span> B <span>AS</span> (<br>    <span>SELECT</span> <span>*</span>,ROW_NUMBER() <span>OVER</span>(<span>ORDER</span> <span>BY</span> ID <span>ASC</span>) <span>AS</span> ROW_NUM<br>    <span>FROM</span> A <span>WITH</span>(NOLOCK)<br>)<br><span>SELECT</span> <span>*</span> <br><span>FROM</span> B <span>WITH</span>(NOLOCK)<br><span>WHERE</span> ROW_NUM <span>BETWEEN</span> <span>31</span> <span>AND</span> <span>40</span><br><span><br></span><span>--</span><span>我一般这么写</span><span><br></span><span>SELECT</span> <span>*</span> <span>FROM</span> (<br>    <span>SELECT</span> <span>*</span>,ROW_NUMBER() <span>OVER</span>(<span>ORDER</span> <span>BY</span> ID <span>ASC</span>) <span>AS</span> ROW_NUM<br>    <span>FROM</span> A <span>WITH</span>(NOLOCK)<br>) B <br><span>WHERE</span> ROW_NUM <span>BETWEEN</span> <span>31</span> <span>AND</span> <span>40</span>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn