sql - Is it possible to automaticly have in a row a substraction between two MYSQL variables -
i have :
+----------+------+-----+--------+ | image_id | | bad | result | +----------+------+-----+--------+ | 1 | 10 | 2 | x | +----------+------+-----+--------+ | 2 | 4 | 1 | y | +----------+------+-----+--------+
where x , y calculated automaticaly respectively 10 - 2 , 4 - 1. (good - bad) -avoid negative number if possible-
i value change if values (good or bad) changes well.
+----------+------+-----+--------+ | image_id | | bad | result | +----------+------+-----+--------+ | 1 | 10 | 2 | x | +----------+------+-----+--------+ | 2 | 4 | 1 | y | +----------+------+-----+--------+
i can in php there way directly mysql ?
calculate result , return no less zero, avoiding negative numbers:
select image_id, good, bad, greatest(good-bad, 0) result `table`;
Comments
Post a Comment