有没有更快的方法来做到这一点?
$data1 = mysql_query(
"SELECT * FROM table1 WHERE id='$id' AND type='$type'"
) or die(mysql_error());
$num_results = mysql_num_rows($data1);
$data2 = mysql_query(
"SELECT sum(type) as total_type FROM table1 WHERE id='$id' AND type='$type'"
) or die(mysql_error());
while($info = mysql_fetch_array( $data2 )){
$count = $info['total_type'];
}
$total = number_format(($count/$num_results), 2, ',', ' ');
echo $total;
干杯!
最佳答案
查看您的查询,我认为您正在寻找类似的内容:
SELECT SUM(type) / COUNT(*) FROM table1 WHERE ...
关于php - 更快的 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4789131/