如何在不选择所有行的情况下获取行数?
我如何获得像 mysql_num_rows
这样的行数,但没有 mysql 资源可供使用,因为我不知道我的 web 应用程序的未来规模,并且可能需要一个小时才能获得该数字行;)
谢谢!
How can i get the number of rows like mysql_num_rows
but without having a mysql resource to work from, because i don't know the future scale of my webapp and it could take an hour just to get the number of rows ;)
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
SELECT COUNT(*) AS num_rows FROM tblName;
- 并从该语句中检索num_rows
列。SELECT COUNT(*) AS num_rows FROM tblName;
- and just retrievenum_rows
column from that statement.使用 COUNT 进行 SQL 查询,例如:
Make an SQL query with COUNT, e.g.:
万一您的“实际”sql 查询中有 LIMIT 子句并且想知道项目总数(例如,在进行某种分页时),您可能也会对 SQL_CALC_FOUND_ROWS 和 FOUND_ROWS()
Just in case you have a LIMIT clause in your "actual" sql query and want to know the toal number of items (e.g. when doing some kind of pagination) you might also be interested in SQL_CALC_FOUND_ROWS and FOUND_ROWS()
请参阅 http://dev.mysql.com /doc/refman/5.0/en/group-by-functions.html#function_count 了解 COUNT(*) 和 COUNT(id) 之间的差异
See http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_count for differences between COUNT(*) and COUNT(id)
SELECT COUNT(*) AS number FROM table
将返回 1 行,其中包含一个名为 number 的字段,该字段保存表中的行数。
SELECT COUNT(*) AS number FROM table
Will return 1 row with a field called number which holds the number of rows in the table.