CREATE TABLE users (id int, name varchar(20), age int);
INSERT INTO users VALUES (1, 'Bob', 19);
INSERT INTO users VALUES (2, 'Jack', 25);
INSERT INTO users VALUES (3, 'Paul', 15);
INSERT INTO users VALUES (4, 'Steve', 35);
INSERT INTO users VALUES (5, 'Mark', 17);
SELECT * FROM users WHERE age > 18;
+------+-------+------+
| id | name | age |
+------+-------+------+
| 1 | Bob | 19 |
| 2 | Jack | 25 |
| 4 | Steve | 35 |
+------+-------+------+
3 rows in set (0.00 sec)
SELECT FOUND_ROWS() as num_of_rows_found;
+-------------------+
| num_of_rows_found |
+-------------------+
| 3 |
+-------------------+
1 row in set (0.00 sec)
4条答案
按热度按时间u0sqgete1#
您可能需要使用
FOUND_ROWS()
函数。示例:
mkshixfv2#
您必须在查询中使用FOUND_ROWS和SQL_CALC_FOUND_ROWS:http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows
llmtgqce3#
FOUND_ROWS和SQL_CALC_FOUND_ROWS已经过时,不会在MySQL 8.0.17以上的版本中使用。
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows
hiz5n14c4#
您可以尝试FOUND_ROWS()函数。