【发布时间】:2013-12-04 19:54:02
【问题描述】:
我的问题与此类似: Need a row count after SELECT statement: what's the optimal SQL approach?
但我想从查询中获取总行数,然后使用 limit 创建分页,所以我不能使用返回的行。 从一个简单的查询:
select * from res_groups
我进入了这个:
select a.*, (select count(1) from (select * from res_groups) e) total
from (select * from res_groups) a limit 10 offset 10;
或者我可以使用简单的方法并进行两个查询:
select * from res_groups limit 10;
select count(*) from res_groups;
第一个查询是否会执行?恐怕 res_groups 的查询会被执行两次?
还有其他方法吗? ps:我用的是postgres,我知道mysql有FOUND_ROWS()
【问题讨论】:
标签: postgresql select count