1

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 ?

4
  • 5
    What is that supposed to mean? Commented Jul 29, 2010 at 13:17
  • 2
    Sorry, I don't understand. Can you present a before and after overview of the data to give a better idea. Also, I take it you mean 'subtract' and not 'substitute'? Commented Jul 29, 2010 at 13:20
  • @NullUserException: You phrased that much more politely than I would have Commented Jul 29, 2010 at 13:20
  • WHERE smt='$smt - smth field' ,but in SQL ,without PHP (I know how to do it with PHP).Sorry for my bad English Commented Jul 29, 2010 at 13:20

4 Answers 4

1

Try

$sql = "SELECT (smt-smth) as diff, smth, smths, smthss FROM sometbl WHERE smt='$smt' AND smts='$smts'";
Sign up to request clarification or add additional context in comments.

Comments

1

just subtract ($smt-smth)

SELECT  ($smt-smth) as differance, `smth`,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'

Comments

0
$sql = "SELECT ($smt - smth) as smth,`smths`,`smthss` FROM sometbl WHERE `smt`='$smt' AND `smts`='$smts'";

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.