有没有更快的方法来做到这一点?更快的mysql查询
$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;
干杯!
`COUNT(*)`是稍微好一点(因为它不依赖于现场数据,因为它是'COUNT(ID)`) – zerkms 2011-01-25 01:37:42
无加入两个查询的方法呢? – Alfie 2011-01-25 01:38:00