有沒有更快的方法來做到這一點?更快的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