以下是我目前选择陈述的内容:
$sql17="SELECT SUM(TotalProfit)-('$sum14','$sum13') AS TotalProfit FROM jwtdriversbank2";
我可以毫无问题地减去一个这样的变量:
$sql17="SELECT SUM(TotalProfit)-'$sum14' AS TotalProfit FROM jwtdriversbank2";
但我希望能够减去几个变量,我该怎么办?
答案 0 :(得分:1)
喜欢这个吗?
$sql17="SELECT SUM(TotalProfit)-'$sum14'-'$sum13' AS TotalProfit FROM jwtdriversbank2";
通过直接注入变量来构建SQL查询时要小心,尽可能使用预处理语句。
答案 1 :(得分: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";