0

这是我目前的选择声明:

$sql17="SELECT SUM(TotalProfit)-('$sum14','$sum13') AS TotalProfit FROM jwtdriversbank2";

我可以毫无问题地减去一个这样的变量:

$sql17="SELECT SUM(TotalProfit)-'$sum14' AS TotalProfit FROM jwtdriversbank2";

但是我希望能够减去几个变量,我该怎么做????

4

2 回答 2

1

像这样?

$sql17="SELECT SUM(TotalProfit)-'$sum14'-'$sum13' AS TotalProfit FROM jwtdriversbank2";

通过像这样直接注入变量来构造 SQL 查询时要小心,尽可能使用准备好的语句。

于 2013-07-23T10:59:01.713 回答
1
$sum_to_substract = $sum14+$sum13; //add all vars that you want to substract
$sql17="SELECT SUM(TotalProfit)-'$sum_to_substract' AS TotalProfit FROM jwtdriversbank2";
于 2013-07-23T11:13:29.920 回答