user370306
user370306

Reputation:

SQL Programming

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

Answers (4)

paxdiablo
paxdiablo

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

Pranay Rana
Pranay Rana

Reputation: 176896

just subtract ($smt-smth)

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

Upvotes: 1

Mithun Sreedharan
Mithun Sreedharan

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

Related Questions