我试图在数据库中获得一些选定的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);
由于死亡功能,这会产生如下错误。
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
我能做什么,解决方案是什么?
答案 0 :(得分:3)
AND
之后您错过了Program='PSC'
:
SELECT SUM(Money) as TotalMoney
FROM accounts
WHERE Program='PSC'
AND BranchId='10'
AND ExamYear='2013'
答案 1 :(得分:0)
您需要使用条件运算符AND/OR
来支持您的条件
SELECT SUM(Money) as TotalMoney
FROM accounts
HAVING Program='PSC' and
BranchId='10' and
ExamYear='2013'