这是我目前的选择声明:
$sql17="SELECT SUM(TotalProfit)-('$sum14','$sum13') AS TotalProfit FROM jwtdriversbank2";
我可以毫无问题地减去一个这样的变量:
$sql17="SELECT SUM(TotalProfit)-'$sum14' AS TotalProfit FROM jwtdriversbank2";
但是我希望能够减去几个变量,我该怎么做????
像这样?
$sql17="SELECT SUM(TotalProfit)-'$sum14'-'$sum13' AS TotalProfit FROM jwtdriversbank2";
通过像这样直接注入变量来构造 SQL 查询时要小心,尽可能使用准备好的语句。
$sum_to_substract = $sum14+$sum13; //add all vars that you want to substract
$sql17="SELECT SUM(TotalProfit)-'$sum_to_substract' AS TotalProfit FROM jwtdriversbank2";