gpt4 book ai didi

php - 哪个更快/更聪明,为什么是 : COUNT(*) or storing the numbers each the do something

转载 作者:行者123 更新时间:2023-11-29 05:44:48 26 4
gpt4 key购买 nike

PHP

$total_points = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM account WHERE id='$id'"),0)

Mysql账户表

|user_id|

mysql积分表

|id | user_id | points |

PHP

$total_points = mysql_query("SELECT points FROM account WHERE id='$id'");

Mysql账户表

|user_id| points |

Mysql积分表

|id | user_id | points |

最佳答案

存储变量可能会更快,但这也意味着不断更新它,从长远来看,这可能会降低效率/变慢。

不过,使用 COUNT(id) 会比 COUNT(*) 好得多。所以我的投票是使用 COUNT(id) :)

关于php - 哪个更快/更聪明,为什么是 : COUNT(*) or storing the numbers each the do something,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3340923/

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