Three paging methods for SQL Server

Source: Internet
Author: User
If exists (select * From sysobjects where name = 'webname') Drop table stuwebnamegocreate table stuwebname (stuid int identity (1, 1) primary key, stuname varchar (50) not null, stupassword varchar (50) not null, stusex char (2) default ('male'), stuno int not null) godeclare @ ID intset @ ID = 1 while (@ ID <100) begininsert into stuwebname (stuname, stupassword, stusex, stuno) values ('zhang san' + convert (varchar (50), @ ID), '123', 'mal', 123) set @ ID = @ ID + 1 endgoselect * From stuwebnamego ------------------------------------------------------- the most common sorting types (five pieces of data on each page on the first page) first, use the row_number function to add sequence numbers to each column, and then sort select * from (select row_number () over (order by stuid) as B, * From stuwebname) as awhere B> (2-1) * 5 and B <= 2*5 go -- first query the first 10 rows, then reverse query the first 5 rows, and finally reverse query the data) select * from (select top 5 * from (select top 10 * From stuwebname order by stuid ASC) as t order by stuid DESC) as T order by stuid ascgo -- first query the first six rows, and then obtain the maximum value of stuid select top 5 * From stuwebnamewhere (stuid> = (select max (stuid) from (select top (5*1) + 1) stuidfrom stuwebname order by stuid) as t) order by stuidgo

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.