我想要php分页从sql server 2008获取数据,
1. mysql 可以 limit n,m ,sql server没有
2. 要分页获取 union 后的数据, 网上看到有用rownum 和 top 的,请问怎么与union结合实现呢
我的结果集类似于
(select A,B,C,D from t1) union (select '100' as A ,B,C,D from t2) union (select A,B,C,D from t3)
想限制每次返回结果集的 哪一条到哪一条
回复讨论(解决方案)
这样写:
$sql = '你的sql查询指令';$start = 1; //起始偏移$pagesize = 20; //每页行数$sqls =<<< SQLSELECT * FROM (SELECT A.*, ROWNUM RN FROM ($sql) A WHERE ROWNUM < $start+$pagesize)WHERE RN >= $startSQL;$sqls 就是最终执行的查询语句
理解了,原来我的问题在于 不知道给union 的结果取个别名,谢谢版主大人~~
最后结合百度 我是这样写的
SELECT * FROM ( SELECT * , ROW_NUMBER() OVER (ORDER BY A DESC) AS rn FROM ($sql) AS s1)AS s2 where rn between $from and $to

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec

PHP traits enable code reuse in single inheritance contexts, offering benefits like reusability and simplified inheritance. They can be effectively combined with traditional inheritance to enhance class flexibility and modularity.

PHP does not support multiple inheritance but uses interfaces and traits as alternatives to achieve similar functionality, avoiding issues like the diamond problem.

Inheritance in PHP allows classes to inherit properties and methods, promoting code reuse and hierarchical organization. Key benefits include reusability, abstraction, and polymorphism. Common mistakes to avoid are overuse of inheritance and ignoring

The article discusses three main error types in programming: syntax, runtime, and logical errors. It explains their causes, prevention strategies, impacts on performance and user experience, and methods for diagnosis and resolution.

Article discusses PHP and HTML interaction, best practices for embedding PHP in HTML, dynamic HTML content generation, and recommended development tools.

The article discusses the differences between for and foreach loops in PHP, focusing on syntax, usage, control, and performance. Foreach is preferred for array iteration due to simplicity and efficiency, but for loops are better for index-based opera

The article discusses the crucial role of the PHP parser in script execution, focusing on its tasks in syntax analysis, error handling, and code optimization, and how its efficiency impacts web application performance.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

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