Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否检索列中少数选定行的总和?_Php_Mysql_Sql_Database - Fatal编程技术网

Php 是否检索列中少数选定行的总和?

Php 是否检索列中少数选定行的总和?,php,mysql,sql,database,Php,Mysql,Sql,Database,我试图在数据库中获取选定的几行Money列的总和 下面是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/><

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

下面是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);

我能做什么?解决方法是什么?

您错过了
程序
之后的

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

您错过了一个
程序
之后的

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

您需要使用条件运算符
和/或类似的

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

您需要使用条件运算符
和/或类似的

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

请,请,请停止使用
mysql.*
。出于安全和其他原因,请改用PDO或mysqli。检查并请,请,请停止使用
mysql.*
。出于安全和其他原因,请改用PDO或mysqli。检查一下,谢谢@mishik我没有看到,为此我被困了一个小时…无论如何谢谢…@user2557992-感谢并支持你可以接受答案。@user2557992如果这对你有用,你应该接受答案。…)谢谢@mishik我没有看到,为此我被困了一个小时…无论如何谢谢…@user2557992-感谢并支持你可以接受答案。@user2557992如果这对你有用,你应该接受答案。…)