gpt4 book ai didi

php - 更快的 mysql 查询

转载 作者:行者123 更新时间:2023-11-29 14:55:13 25 4
gpt4 key购买 nike

有没有更快的方法来做到这一点?

$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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com