sql UPDATE, a calculation is used multiple times, can it just be calculated once?

Posted by Zachery Delafosse on Stack Overflow See other posts from Stack Overflow or by Zachery Delafosse
Published on 2010-06-14T16:50:58Z Indexed on 2010/06/14 16:52 UTC
Read the original article Hit count: 204

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql