gpt4 book ai didi

php - 检索列的几个选定行的总和?

转载 作者:太空宇宙 更新时间:2023-11-03 12:26:13 25 4
gpt4 key购买 nike

我试图获取数据库中 Money Column 的几行选定行的总和。

sql如下。

$sql_total_money = "SELECT SUM(Money) as TotalMoney FROM accounts WHERE Program='PSC' BranchId='13' and ExamYear='2013'";
$result_total_money=mysql_query($sql_total_money,$link)or die($sql_total_money."<br/><br/>".mysql_error());
$row_total_money=mysql_fetch_array($result_total_money);

由于 die 函数,这会给出如下错误。

SELECT SUM(Money) as TotalMoney FROM accounts WHERE Program='PSC' BranchId='10' and ExamYear='2013'

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BranchId='10' and ExamYear='2013'' at line 1

我能做什么,解决方案是什么?

最佳答案

您在 Program='PSC' 之后错过了一个 AND:

SELECT SUM(Money) as TotalMoney
FROM accounts
WHERE Program='PSC'
AND BranchId='10'
AND ExamYear='2013'

关于php - 检索列的几个选定行的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17512007/

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