Reputation:
I have this select sql query:
$sql = "SELECT `smth`,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'";
How to substract the smth field from $smt ?
Upvotes: 1
Views: 179
Reputation: 881403
To subtract the smth
field from smt
in the where
clause (as you indicate in one of the comments), use:
$sql = "SELECT `smth`,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' - `smth` AND `smts`='$smts'";
This will pass the:
- `smth`
as-is through to the DBMS, not interpreted by PHP.
Upvotes: 0
Reputation: 176896
just subtract ($smt-smth)
SELECT ($smt-smth) as differance, `smth`,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'
Upvotes: 1
Reputation: 51272
Try
$sql = "SELECT (smt-smth) as diff, smth, smths, smthss FROM sometbl WHERE smt='$smt' AND smts='$smts'";
Upvotes: 1
Reputation: 1499
$sql = "SELECT ($smt - smth) as smth,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'";
Upvotes: 0