gpt4 book ai didi

mysql - 按 2 个日期字段一起排序

转载 作者:行者123 更新时间:2023-12-01 00:40:16 24 4
gpt4 key购买 nike

表:

id | date_in             | date_out            |
1 | 2016-01-01 12:00:00 | 2016-01-03 12:00:00 |
2 | 2016-01-01 12:00:00 | 2016-01-02 12:00:00 |

我需要一个返回结果如下的查询:

id | alias
1 | 2016-01-01 12:00:00
2 | 2016-01-01 12:00:00
2 | 2016-01-02 12:00:00
1 | 2016-01-03 12:00:00

最佳答案

我会假设类似union 的东西就足够了,因为没有上下文我只能假设这就是您要找的东西?

SELECT t.id, t.date_in AS alias FROM test t
UNION ALL
SELECT t2.id, t2.date_out AS alias FROM test t2
ORDER BY alias ASC;

会给你如下结果:

+----+---------------------+
| id | alias |
+----+---------------------+
| 2 | 2016-01-01 12:00:00 |
| 1 | 2016-01-01 12:00:00 |
| 2 | 2016-01-02 12:00:00 |
| 1 | 2016-01-03 12:00:00 |
+----+---------------------+
4 rows in set (0.00 sec)

关于mysql - 按 2 个日期字段一起排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34416752/

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