Home > Database > Mysql Tutorial > sqlServer 查询表中31到40的记录,考虑id不连续的情况

sqlServer 查询表中31到40的记录,考虑id不连续的情况

WBOY
Release: 2016-06-07 15:39:57
Original
2015 people have browsed it

sqlServer 查询 表中31到40的 记录 , 考虑 id不 连续 的 情况 写出一条sql语句输出表UserInfo表中31到40 记录 (数据库为SQL Server,以自动增长的ID作为主键,注意ID可能不是 连续 的)? 根据题意理解: 本质就是写分页 查询 : 每页条数:10条; 当前页码

sqlServer   查询表中31到40的记录考虑id不连续情况

写出一条sql语句输出表UserInfo表中31到40记录(数据库为SQL Server,以自动增长的ID作为主键,注意ID可能不是连续的)?

根据题意理解:

本质就是写分页查询

每页条数:10条;

当前页码:4页;

sqlServer   查询表中31到40的记录,考虑id不连续的情况sqlServer   查询表中31到40的记录,考虑id不连续的情况

<span> 1</span> <span>//</span><span>第一种:</span>
<span> 2</span> <span>select</span> * <span>from</span>
<span> 3</span>  (<span>select</span> ROW_NUMBER() over(order by Id asc) <span>as</span> num,* <span>from</span> UserInfo)<span>as</span><span> u
</span><span> 4</span>  <span>where</span><span> u.num
</span><span> 5</span> <span> between
</span><span> 6</span>  <span>10</span>*(<span>4</span>-<span>1</span>)+<span>1</span>
<span> 7</span> <span> and
</span><span> 8</span>  <span>10</span>*<span>4</span>
<span> 9</span> <span>//</span><span>第二种:</span>
<span>10</span> <span>select</span> top <span>10</span> * <span>from</span><span> UserInfo 
</span><span>11</span> <span>where</span> Id not <span>in</span>
<span>12</span> (<span>select</span> top (<span>10</span>*<span>3</span>) id <span>from</span><span> UserInfo order by Id)
</span><span>13</span> order by Id
Copy after login
View Code

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template