Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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 ?
smt
Try
$sql = "SELECT (smt-smth) as diff, smth, smths, smthss FROM sometbl WHERE smt='$smt' AND smts='$smts'";
Add a comment
just subtract ($smt-smth)
SELECT ($smt-smth) as differance, `smth`,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'
$sql = "SELECT ($smt - smth) as smth,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'";
To subtract the smth field from smt in the where clause (as you indicate in one of the comments), use:
smth
where
$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.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
smt='$smt - smth field' ,but in SQL ,without PHP (I know how to do it with PHP).Sorry for my bad English