MySql,Sqlserver,Oracle数据的分页语句
在实际项目中分页是常见的不能再说了,这里我总结了MySql,SqlServer,Oracle这三个数据库的sql分页语句 在这三个数据库中,个人觉得MySql的分页语句是最简单的,只用一个limit关键字就能完成 MySql数据库: select * from test limit 5,5; test:表名 第一个
在实际项目中分页是常见的不能再说了,这里我总结了MySql,SqlServer,Oracle这三个数据库的sql分页语句
在这三个数据库中,个人觉得MySql的分页语句是最简单的,只用一个limit关键字就能完成
MySql数据库:
select * from test limit 5,5;
test:表名
第一个参数5:从表中的第几行开始查,从0开始数
第二个参数5:查询出多少条记录
在项目中运用时,如果一个页面指定了显示多少条记录,通常第二个参数不会改变,都是该变的第一个参数
计算每页的公式:这里都是每页显示5条记录
第一页:(1-1)*5
第二页:(2-1)*5
第三页:(3-1)*5
第N页:(n-1)*5
公式:
开始的行数=(当前页-1)*每页显示的行数
所以最后在代码中的sql语句可以写为:
int pageSize=5;//每页显示行数
int pageNo=4;//当前页
int num=(pageNo-1)*pageSize;//开始查找的行
select * from test limit num,pageSize;
我了解的MySql数据的分页语句就只有这一种了
在SqlServer数据库中目前我了解的sql分页语句有两种
第一种:
select top(5) * from test where id not in( select top((2-1)*5) id from test )
第二种:
select * from( select ROW_NUMBER() Over(order by id) as rownum,* from test ) t where rownum between (2-1)*5+1 and 2*5
在Oracle数据库中我了解的一只有两种:
第一种:
select * from ( select t.*,rownum rn from emp t ) t1 where rn>(2-1)*3 and rn <p>也可以使用between</p> <pre class="brush:php;toolbar:false">select * from ( select t.*,rownum rn from emp t ) where rn between (2-1)*3+1 and 2*3
第二种:
select * from ( select t.*,rownum rn from ( select * from emp )t where rownum(2-1)*3
这两种比较起来,个人认为第一种查询相对比较快,因为第一种只查询了两次,而第二种查询的三次
至于怎样使用,看个人比较适合哪一种了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.
