I have a query running on a large table, so I need it to run as optimized as possible, and would like to clean up this particular equation.
SET points = IF(
(20 - ABS(pick.guessed_rank - team.rank)) < 0,
0,
(20 - ABS(pick.guessed_rank - team.rank))
)
How can i improve this to save the ABS(pick.guess_rank - team.rank)
to a variable so my update can look more something like:
@diff = ABS(pick.guess_rank - team.rank;
SET points = IF(@diff < 0, 0, @diff);
Or perhaps there is a better solution than using an if statement for this, but an example of how to use a variable in this situation would still be helpful.