我发现很难决定用 where 语句过滤的表中某些特定记录的最快计数方法是什么 这是我的代码,这是查询:
$type_mo3ln_malk = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='malk'"));
$type_mo3ln_mswg = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='mswg'"));
$type_mo3ln_mktb = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='mktb'"));
$type_mo3ln_wkeel = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='wkeel'"));
$type_mo3ln_no = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='0'"));
执行计数的函数是在 php 中预定义的函数
我正在考虑使用 count() 函数,但我想知道我是否可以像 Mr.Hates 在这里建议的那样仅对某些特定行使用 Sum 函数 Get record counts for all tables in MySQL database
最佳答案
SELECT COUNT(*) FROM `table` WHERE `whatever`='whatever';
将返回一行(而不是超过 9000 行),其中包含基于您设置的规则的正确计数。
关于php - 使用mysql计算大表的最快方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11705124/