gpt4 book ai didi

MySQL 查询 ORDER BY DateTime 问题

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

我正在尝试按大于现在升序然后小于现在降序的最新更新日期时间对查询进行排序。这是我想要的输出:

2014-06-01 00:00:00
2014-06-04 00:00:00
2014-06-05 00:00:00
2014-06-06 00:00:00
2014-05-19 00:00:00
2014-05-15 00:00:00
0000-00-00 00:00:00

但我得到的是这个:

2014-06-01 00:00:00
2014-06-04 00:00:00
2014-06-05 00:00:00
2014-06-06 00:00:00
0000-00-00 00:00:00
2014-05-15 00:00:00
2014-05-19 00:00:00

我正在使用的查询是这样的:

SELECT lastupdated FROM users ORDER BY lastupdated > NOW() DESC, lastupdated ASC;

最佳答案

你可以用 UNION 来完成:

SELECT lastupdated 
FROM users
WHERE lastupdated > NOW()
ORDER BY lastupdated DESC

UNION

SELECT lastupdated
FROM users
WHERE lastupdated <= NOW()
ORDER BY lastupdated ASC;

关于MySQL 查询 ORDER BY DateTime 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23765659/

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