SQL Server Three paging methods

Source: Internet
Author: User

IF EXISTS (SELECT * from SYSOBJECTS WHERE NAME = ' stuwebname ') DROP table stuwebnamegocreate table Stuwebname (stuid INT IDEN  Tity (+) PRIMARY key,stuname varchar (2) not null,stupassword varchar (+) not null,stusex CHAR ("male"), Stuno INT Not NULL) godeclare @ID intset @ID =1while (@ID <100) BEGIN INSERT into Stuwebname (Stuname,stupassword,stusex,stuno) VAL UES (' Zhang San ' +convert (VARCHAR), @ID), ' 123 ', ' Male ', 0902 ' SET @[email protected]+1endgoselect * from Stuwebnamego-------------------------------------------------------Several of the most common sort sorts (first page of five data per page)---------------------- ---------------------------------First Use the Row_number function to sequence the columns in each column and then sort the select * FROM (select Row_number () over (ORDER by Stuid) as b,* From Stuwebname) as Awhere b> (2-1) and b<=2*5 go--first query the first 10 lines, then reverse the first 5 lines, and finally in reverse (the data back) SELECT * FROM (select TOP 5 * FR OM (SELECT TOP Ten * from Stuwebname ORDER by Stuid ASC) as-t order by Stuid DESC) as-t order by Stuid ascgo--first 6 rows, let back take Stuid The maximum value of the Select TOP 5 *from stuwebnamewhere (Stuid >= (SelecT MAX (Stuid) from (SELECT TOP ((5*1) +1) Stuid from Stuwebname Order by Stuid) as T) ORDER by Stuidgo 

  

SQL Server Three paging methods

Related Article

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.