传统的查询方法
SELECT COUNT(*) FROM users WHERE name LIKE ‘a%’;
SELECT name, email FROM users WHERE name LIKE ‘a%’ LIMIT 10;
使用SQL_CALC_FOUND_ROWS
SELECT SQL_CALC_FOUND_ROWS name, email FROM users WHERE name LIKE ‘a%’ LIMIT 10;
SELECT FOUND_ROWS();
好处
- 只进行一次复杂的查询
- 可以获取到不带limit的数据条数