gpt4 book ai didi

mysql - 将两列合并为一列,仅显示所需数据

转载 作者:行者123 更新时间:2023-11-29 20:13:40 26 4
gpt4 key购买 nike

我可以从每一列获取一些数据,然后使用 mysql 查询将其存储在一个结果列中吗?

Table
Truck Number, Depart time, Arrive time
0001,'2016-10-05 07:15:00','2016-10-05 10:10:00'
0002,'2016-10-05 08:15:00','2016-10-05 09:30:00'
0003,'2016-10-04 19:15:00','2016-10-05 08:45:00'

我只想要从 '2016-10-05 08:00:00' 到 '2016-10-05 08:50:00' 出发或到达的卡车

我想要的输出是

Truck, Time
0002 '2016-10-05 08:15:00'
0003 '2016-10-05 08:45:00'

如果可能的话,也提供时间来源的专栏。

最佳答案

SELECT  T.TRUCKNUMBER,
CASE WHEN DEPART BETWEEN '2016-10-05 08:00:00' AND '2016-10-05 08:50:00' THEN DEPART
ELSE ARRIVE
END AS TIME ,
CASE WHEN DEPART BETWEEN '2016-10-05 08:00:00' AND '2016-10-05 08:50:00' THEN 'DEPART'
ELSE 'ARRIVE'
END AS SourceColumn

FROM T WHERE DEPART BETWEEN '2016-10-05 08:00:00' AND '2016-10-05 08:50:00' OR
ARRIVE BETWEEN '2016-10-05 08:00:00' AND '2016-10-05 08:50:00'

结果

+-------------+---------------------+--------------+
| TRUCKNUMBER | TIME | SourceColumn |
+-------------+---------------------+--------------+
| 2 | 2016-10-05 08:15:00 | DEPART |
| 3 | 2016-10-05 08:45:00 | ARRIVE |
+-------------+---------------------+--------------+

关于mysql - 将两列合并为一列,仅显示所需数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39929502/

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