您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MYSQL的FOUND_ROWS()函数_MySQL

2025/6/17 19:23:34发布15次查看
mysql 4.1中新增了found_rows()函数,这个函数的说明是这样的:
for a select with a limit clause, the number of rows that would be returned were there no limit clause
a select statement may include a limit clause to restrict the number of rows the server returns to the client. in some cases, it is desirable to know how many rows the statement would have returned without the limit, but without running the statement again. to obtain this row count, include a sql_calc_found_rows option in the select statement, and then invoke found_rows() afterward:
比如说有段sql需要取出一张表的前10行,同时又需要取出符合条件的总数。这在某些翻页操作中很常见
plain text
code:
select sql_calc_found_rows * from tbl_name
where id> 100 limit 10;
在上一查询之后,你只需要用found_rows()就能获得查询总数,这个数目是抛掉了limit之后的结果数:
plain text
code:
select found_rows();
其中第一个sql里面的sql_calc_found_rows不可省略,它表示需要取得结果数,也是后面使用found_rows()函数的铺垫
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product