这是可能获得总行数计数与偏移限制

这是可能获得总行数计数与偏移限制

本文介绍了这是可能获得总行数计数与偏移限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey Guyz这是有可能获得带偏移限制的总行数。

Hey Guyz Is this possible to get total number of rows count with offset limit

场景

SELECT * FROM users limit 0,5;

此查询包含300条记录,但问题是如果我使用offset调用此查询,结果将显示只有5条记录,我不想两次写一个查询。一个用于寻呼限制和其他总计记录计数...

This Query contain 300 records but the issue is if i call this query with offset the result will be show only 5 record and i don't want to write a Query in twice time. one for paging limit and other for total no of record count...



SELECT * FROM users limit 0,5; // paging
SELECT count(*) FROM users; // count

我必须合并此查询或帮助是绝对赞赏

i have to merge this Queries or helps are definitely appreciated

推荐答案

您可以像下面这样使用SQL_CALC_FOUND_ROWS:

You can use SQL_CALC_FOUND_ROWS like this

SELECT SQL_CALC_FOUND_ROWS * FROM users limit 0,5;

在应用任何LIMIT子句之前获取行计数。它需要另一个查询来获取结果,但该查询可以是

It gets the row count before applying any LIMIT clause. It does need another query to fetch the results but that query can simply be

SELECT FOUND_ROWS()

,因此您不必重复复杂的查询。

and hence you don't have to repeat your complicated query.

这篇关于这是可能获得总行数计数与偏移限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:17