The strongest data paging method in history

zhaozj2021-02-16  42

Seeing countless paging methods for their predecessors, there is no skill, the most like this post http://www.9cbs.net/develop/read_article.asp?id=18627 Paging method is the most Let me not let me watch the post of my predecessors, all because of the SQL of the database, and the SQL Server, Access, etc., the rookie database does not have a secondary column such as RowID, _n_, OBS, etc., empty BetWeen operations. It is true that there is no datagram, which is like Except, and it is true that there are countless heroes.

Even the database SQL, drawing the database with the SQL syntax of the previous N-recorded SQL syntax, such as the syntax, the data page n ****, and the key problem with the data paging is to take the N records. The syntax is deeply thoughtful, and finally Pefeve, this is a lot of guidance.

Take the Dafa after the N-records after the collection column: Suppose 1. There is a SQL statement will generate 1000 records (SELECT unique ID, other fields of the FROM table set WHERE Condition ORDER BY Sort) 2. The 20 records of each page are displayed 3. The current display Page 5 pages

Decree as follows: select * from (SELECT * FROM (SELECT * 4 Unique ID, other fields of the FROM table set Where conditions ORDER BY Sort) AS A Union All Select * from (SELECT TOP 20 * 5 Unique ID, other fields of FROM table Set WHERE Condition ORDER BY Sort) AS B) A Group By Unique ID, Other Fields Having Count (Unique ID) = 1 ORDER BY Sort

Run this SQL, after the recording set, the N-recorded Dafa is finished.

Detailed description:

Key application techniques for this SQL statement lies in union all and grouping conditions filtering statements

Everyone can make a general paging method according to this skill, such as directly from the user to SQLSTR (SQL statement), NumperPage (display per page), Currpage, you can organize it in again SQL page statement

Remarks: If the current page is 1, you don't need to run the SQL. Direct TOP is OK. Due to the environment, the SQL performance cannot be tested, but it is not necessary to run the platform in Access, SQL Server can run, other databases The platform only needs to change the TOP key, you should run in place.

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

New Post(0)