gpt4 book ai didi

mysql 查询,对两个日期列进行排序并跟踪它来自的原始列

转载 作者:行者123 更新时间:2023-11-29 09:00:35 24 4
gpt4 key购买 nike

这是我的任务的简化版本。我有一个包含用户进出时间戳的表。表列有:id、用户名、timeIn、timeOut。我想创建一个报告,按照事件的输入或输出顺序对结果进行排序,并跟踪它是输入还是输出以供打印输出。到目前为止,我唯一的想法是创建两个数组以及 inTimeArray 和 outTimeArray,然后循环它们,

if (inTimeArray > outTimeArray) {
print time in: timestamp;
} else {
print timeout:;
}

输出约翰在:时间露西:时间史蒂夫:时间露西出来:时间乔尔在:时间史蒂夫·奥特:时间露西:时间等等

最佳答案

您可以在查询中使用 case 语句:

select
id,
username,
timeIn,
timeOut,
case when timeIn > timeOut then timeIn else timeOut end as timestamp
from
users

然后,您可以比较时间戳是否= timeIn 或 timeOut。此外,您可以添加另一列:

case when timeIn > timeOut then 0 else 1 end as IsTimeOut

无论哪种方式都有效,真的。

关于mysql 查询,对两个日期列进行排序并跟踪它来自的原始列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8745622/

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