SQL Server queries the records from 31 to 40 in the table, considering the disconsecutive IDs.

Source: Internet
Author: User
SQL Server queries 31 to 40 records in the table, and writes an SQL statement to output 31 to 40 records in the UserInfo table in case of discontinuous IDS (the database is SQL Server, and the Automatically increasing id is used as the primary key, note that the ID may not be consecutive )? According to the meaning of the question, the essence is to write paging queries: the number of entries per page: 10; the current page number

SQL Server queries records ranging from 31 to 40 in the table, and writes an SQL statement to output 31 to 40 records in the UserInfo table due to inconsistent IDS (the database is SQL Server, the auto-increment ID is used as the primary key. Note that the ID may not be consecutive )? According to the meaning of the question, the essence is to write paging queries: the number of entries per page: 10; the current page number

SqlServerQueryFrom 31 to 40Record,ConsiderationsNo idContinuousOfSituation

Write an SQL statement output table UserInfo Table 31 to 40Record(The database is SQL Server, and the Automatically increasing ID is used as the primary key. Note that the ID may not beContinuous)?

Understanding Based on question:

The essence is to write pages.Query:

Number of entries per page: 10;

Current page number: 4 pages;

1 // first: 2 select * from 3 (select ROW_NUMBER () over (order by Id asc) as num, * from UserInfo) as u 4 where u. num 5 between 6 10 * (4-1) + 1 7 and 8 10*4 9 // type 2: 10 select top 10 * from UserInfo 11 where Id not in12 (select top (10*3) id from UserInfo order by Id) 13 order by Id

View Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.