Lets say I have these DB rows
id | storage | used | status
1 - 100 - 0 - 1
2 - 1000 - 5000 - 1
I need to compare开发者_运维百科 the rows "storage" and "used"
I want to select rows WHERE status = 1 and Column"storage" > Column"used".
I tried WHERE status = '1' AND storage > used
It should report back row id #1, but it doesnt.
Well, WHERE status=1 AND storage > used
is correct. If you tried it and didn't get back the row with id=1
there's something wrong with your data.
Are storage
and used
numeric columns? Or are they stored as a VARCHAR
(or, gasp, TEXT
)? If so, you won't be able to compare them quite the way you want, and will first have to convert or cast them to numeric types. It would be better to change the type to actually be numeric (i.e., INT
or DECIMAL
or whichever other type is appropriate).
SELECT * FROM `table` WHERE status = '1' AND storage > used
should give you the right solution, like VoteyDisciple mentioned, make sure status
and used
are both of numeric type.
you can use SELECT * FROM
tableWHERE status = '1' AND storage > used
but the data type of the storage and used must be NUMERIC not VARCHAR.
if Still you didn't get correct ans then it should be problem with your data storage structure.
Thanks!
精彩评论