A SQL statement to get a database page

xiaoxiao2021-03-06  73

A statement to get the database page

Select Top 10 b. * from (SELECT TOP 20 Primary button, Sort FROM Name ORDER BY Sort Field DESC) A, Table Name B WHERE B. Primary Key Field = a. Primary key field Order By a. Sort field

10 = number of records per page

20 = (current page 1) * Per page record number

The above statement can achieve paging, but the resulting sequence of the last removed is ascended, and if the result set is designed (for example, time), there are two ways to process.

1. Use the following statement, but efficiency may reduce some

SELECT * FROM table name B, (SELECT TOP 10 primary key field, sort field from (SELECT TOP 20 Primary key field, sort field from Name ORDER BY Sort Field DESC) a ORDER BY Sort Field) c where b. Primary key field = C. Master key field Order by c. Sort field DESC

2. Handled in ADO, move the recordset to the last, then move forward

'' The following is an ASP example

Set Rstemp = Server.createObject ("AdoDb.Recordset")

RSTEMP.Open statement, conn, 1, 1

Rstemp.movelast

For i = 1 to Rstemp.Recordcount

'Review ....

RSTemp.MovePrevious

NEXT

After testing, the above paging method is fast than the use of temporary tables, and is easy to use

转载请注明原文地址:https://www.9cbs.com/read-92499.html

New Post(0)