gpt4 book ai didi

mysql - 选择查询以获取确切的时间戳

转载 作者:可可西里 更新时间:2023-11-01 08:20:37 25 4
gpt4 key购买 nike

如果我有多个时间戳记录,想获取最接近当前日期的时间戳。我应该使用什么确切的查询命令?提前致谢。下面我描述了我最后的查询命令:

mysql> select date_format(time_stamp, '%Y-%m-%d %H:%i:%s' ) as Time_Stamp
from log
where username='test' and Time_Stamp <= NOW();

| 2012-11-23 14:50:28 |
| 2012-11-23 16:39:45 |
| 2012-11-23 16:51:41 |
| 2012-11-23 16:58:43 |
| 2012-11-25 10:12:14 |
| 2012-11-25 12:50:38 |
| 2012-11-25 12:51:20 |
| 2012-11-25 13:15:44 |
| 2012-11-25 17:47:43 |
| 2012-11-26 09:24:46 |
+---------------------+
285 rows in set (0.00 sec)

我只想得到2012-11-26 09:24:46

最佳答案

可能这应该有效(见最后一行):

select date_format(time_stamp, '%Y-%m-%d %H:%i:%s' ) as Time_Stamp
from log
where username='test' and Time_Stamp <= NOW()
ORDER BY Time_Stamp DESC LIMIT 1;

关于mysql - 选择查询以获取确切的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13558440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com