Let's say I have something as basic as
SELECT IF( (1 + 2) >=0, (1 + 2), 0)
FROM DUAL
which will obviously return 3.
Is there a way to NOT repeat the query I want to return (here 1 + 2)?
To put in context, I want to return the number of tasks remaining to do for the current month (at least 4 must be done), but if more than 4 are already done, there is no need to do more so I want to return 0.
What I have done is
IF((4 - IFNULL((LONG QUERY RETURNING THE NUMBER OF TASKS DONE THIS MONTH FOR A PARTICULAR USER ),0)) >= 0,
(4 - IFNULL((LONG QUERY RETURNING THE NUMBER OF TASKS DONE THIS MONTH FOR A PARTICULAR USER ),
0)
But is there a way to not repeat the query since it is long and I don't want the server to execute the same query twice?