Home  >  Article  >  Database  >  分页,直接通过SQL取分页数据_MySQL

分页,直接通过SQL取分页数据_MySQL

WBOY
WBOYOriginal
2016-06-01 13:48:27831browse

bitsCN.com

一个列表页面,之前程序员用了“Wuqi.Webdiyer”的分页插件,慢,且莫明出错。看了下代码,觉得冗余太多,故决定优化一下。

从网上找了些资料,考虑直接在SQL底层,直接只取当前页的数据,再绑定,这样效率应该会高些。

核心的SQL查询语句是这样的:

select top @size * from (@sqlstring) a where @key = (select min(@key) from (select top @end @key from (@sqlstring) a order by @key desc) a) order by @key desc
bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn