I store expressions in variables and interpolate them in several places for this:
$x_sql = '(mytable.field1 + 10)'; $SQL = "SELECT $x_sql AS x FROM mytable WHERE $x_sql < 50";
Or, if you're not worried about inefficiency, use the HAVING clause:
SELECT (mytable.field1 + 10) as x FROM mytable HAVING x < 50;
(probably just as ineffective for the subtitle suggested in another answer).
source share