Mysql最小功能
是否有一个预定义的 MySQL 函数返回其参数值的最小值(MINIMUM(1,16) -> 1)?
更具体地说,我的一个 mysql 表中有一个现场时间列。
每个访问者每 30 秒轮询一次我的服务器进行更新:
UPDATE `mytable` SET `lastUpdate` = NOW() WHERE `id` = ?;
但我也想更新 timeOnSite 列,如下所示:
UPDATE `mytable` SET `timeOnSite` = (
`timeOnSite` + MINIMUM(
TIMESTAMPDIFF(SECOND, lastUpdate, NOW()), 30
)
),
`lastUpdate` = NOW() WHERE `id` = ?;
但问题是没有这样的 MINIMUM 函数,而且我在 MySQL 手册中找不到它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为它被称为
LEAST()
以避免与聚合函数MIN()
混淆。That's because its called
LEAST()
to avoid confusion with the aggregate functionMIN()
.