MySQL-从一组可能的时间戳中选择最近的日期? [英] MySQL - Select most recent date out of a set of several possible timestamps?

查看:155
本文介绍了MySQL-从一组可能的时间戳中选择最近的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用mysql查询:

I would like to know if this is possible using a mysql query:

我有一个称为更新的表.

I have a table called updates.

在更新表中,我有2列idtimestamp.

In the updates table I have 2 columns, id and timestamp.

我有5行,每行都具有相同的id,但日期时间戳不同.此时间戳的一个示例是值:2012-08-04 23:14:09.

I have 5 rows each with the same id but with different date timestamps. An example of this timestamp would be the value: 2012-08-04 23:14:09.

我只想从5个结果中选择最新的时间戳值.这也可以通过说我想选择最接近当前日期和时间的值来解释.我该怎么办?

I would like to select only the most recent timestamp value out of the 5 results. This could also be explained by saying that I would like to select the value that is closest to the current date and time. How could I do this?

推荐答案

SELECT id, timestamp FROM updates ORDER BY timestamp DESC LIMIT 1

这篇关于MySQL-从一组可能的时间戳中选择最近的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆