Danbyization
Danbyization

Reputation: 87

Select sum of column - several variables

Here is what I have at the moment for my select statement:

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

I can subtract one variable like this with no problem:

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

But I want to be able to subtract several variables, how can I do that????

Upvotes: 0

Views: 73

Answers (2)

super pantera
super pantera

Reputation: 165

$sum_to_substract = $sum14+$sum13; //add all vars that you want to substract
$sql17="SELECT SUM(TotalProfit)-'$sum_to_substract' AS TotalProfit FROM jwtdriversbank2";

Upvotes: 1

Like this?

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

Be careful when you're constructing SQL queries by injecting variables directly like this though, use prepared statements where possible.

Upvotes: 1

Related Questions