sql UPDATE, a calculation is used multiple times, can it just be calculated once?
- by Zachery Delafosse
UPDATE `play` SET `counter1` = `counter1` + LEAST(`maxchange`, FLOOR(`x` / `y`) ), `counter2` = `counter2` - LEAST(`maxchange`, FLOOR(`x` / `y`) ), `x` = MOD(`x`, `y`) WHERE `x` `y` AND `maxchange` 0
As you can see, " LEAST(`maxchange`, FLOOR(`x` / `y`) ) " is used multiple times, but it should always have the same value. Is there a way to optimize this, to only calculate once?
I'm coding this in PHP, for the record.