gpt4 book ai didi

php - MySQL SUM 函数

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

我正在尝试获取一列的总和。

我的架构如下...

scheme screen shot

我想获取“bill”的总和。

我有以下内容...

   <?php
$uid = $_SESSION['oauth_id'];
$query = mysql_query("SELECT * FROM `users`, `income`, `outgoings` WHERE users.oauth_uid = '$uid' and income.user_id = '$uid' and outgoings.user_id = '$uid'") or die(mysql_error());
$result = mysql_fetch_array($query);
?>

Outgoings = <?php echo $result["SUM(total)"];

但是,我没有收到任何输出。有人能看出我哪里出错了吗?我的表中肯定有数据。

最佳答案

在决定从选择中返回什么时,必须使用SUM函数。就像这样。

   SELECT SUM(`bill`) FROM `users`, `income`, `outgoings` WHERE users.oauth_uid = '$uid' and income.user_id = '$uid' and outgoings.user_id = '$uid'

关于php - MySQL SUM 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10132110/

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