开发者

Mysql minimum function

开发者 https://www.devze.com 2023-03-25 12:13 出处:网络
Is there a predefined MySQL function that returns minimum of its arguments\' values (MINIMUM(1,16) -> 1)?

Is there a predefined MySQL function that returns minimum

of its arguments' values (MINIMUM(1,16) -> 1)?

To be more specific, I have a time-on-site column in one of my mysql tables.

Every visitor polls my server every 30 sec making an update:

UPDATE `mytable` SET `lastUpdate` = NOW() WHERE `id` = ?;

but I'd like to update also timeOnSite column like this:

U开发者_如何学编程PDATE `mytable` SET `timeOnSite` = (
`timeOnSite` + MINIMUM( 
                   TIMESTAMPDIFF(SECOND, lastUpdate, NOW()), 30
               )
 ),
`lastUpdate` = NOW() WHERE `id` = ?;

But the problem is that there are no such MINIMUM function, and I failed to find it in MySQL manuals.


That's because its called LEAST() to avoid confusion with the aggregate function MIN().

0

精彩评论

暂无评论...
验证码 换一张
取 消