Implement query record paging with standard SQL statements

xiaoxiao2021-03-06  63

In most applications, returning a large number of eligible records are Siki, the most typical is to search. In the search application, the user gives the search criteria, the server detects a record. However, the search often returns a large number of data records. If you are in a web page, you are often implemented by paging, the page provides a page, such as the previous page, the next page, and the like to implement paging. There is now mainly in the following mid-mode to implement paging: 1.EJB's Find method 2. Place all records in the Collection object before displaying the first page, and subsequent pages are taken in memory. 3. Each page is to the database as a repeated query, and then the eligible record is displayed. 4. Save the search results of the previous few pages in memory (often used), follow-up records (these data are not patiently seen), and they are obtained by even databases. 5. Other various Cache mechanisms. We can choose the method suitable for yourself according to the actual situation, and I will introduce you to a standard SQL statement to get the requirements. Such as records from sections 10 to 20 (in the WHERE statement). By this method, there is a necessary condition, and there must be a field that can identify the record sequence, such as ID, TIME, and the like. Below I demonstrate an example: query all records 10 to 20 in the T_Table table, sorted by ID. SQL statement is: select * from t_table t_table t2 where t2.id = 10 and (select count (*) from t_table t2 where t2.id = 10 and (select count (*) from t_table t2 where t2.id < T1.ID and t2.key = '123') <20 and t1.key = '123' The ID in the condition can be exchanged to any field that can identify the record sequence.

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

New Post(0)