分頁原本都會用
SELECT COUNT(*) FROM ... WHERE ....
SELECT ... FROM ... WHERE LIMIT ...
MYSQL的話可以用SQL_CALC_FOUND_ROWS
SELECT SQL_CALC_FOUND_ROWS ... FROM ... WHERE LIMIT ...
在得到数据后,通过FOUND_ROWS()可以得到不带LIMIT的结果数:
SELECT FOUND_ROWS()
但聽說效率比較慢http://hi.baidu.com/thinkinginlamp/item/b122fdaea5ba23f614329b14
-------------------------------------------------------------------------
至於orcal或postgre可以用 COUNT(*) OVER()來組成分頁
SELECT *,COUNT(*) OVER() AS FULLROWCOUNT FROM ... WHERE ... LIMIT