Mysql minimum function
Asked Answered
B

1

18

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:

UPDATE `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.

Bygone answered 2/8, 2011 at 11:15 Comment(1)
the problem of finding answer in manuals raises from not very obvious keyword "least"Bygone
I
31

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

Inquisitionist answered 2/8, 2011 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.