How to count the sum of all the data in a certain field in the table, and how to output the result?
PHP中文网2017-05-16 13:12:29
Thanks for the invitation
$updataquery = "select sum(lv) AS the_result from gti_enews_technology_group" ;
$r=$empire->fetch1($updataquery);
print_r($r);
//打印的结果是Array ( [0] => 252 [the_result] => 252 ) 打印看看是什么就好处理了
某草草2017-05-16 13:12:29
If it is MySQL, there are built-in functions directlySUM
:
SELECT SUM(column) FROM table WHERE conditions;
Reference https://dev.mysql.com/doc/ref...
phpcn_u15822017-05-16 13:12:29
If you directly use SQL statements to sum, it is not good if the data volume is large. Therefore, it is better to take out the value of this field first. If the amount of data is large, sum it up piece by piece and then integrate it.