gpt4 book ai didi

mysql - 从表中获取一组输入的下一个最大时间

转载 作者:行者123 更新时间:2023-11-29 12:34:02 24 4
gpt4 key购买 nike

我有一个像这样的 mysql 表

Name  |  age |     time
------+------+---------
x | 23 | 21:00:01
y | 67 | 23:34:43
z | 90 | 12:45:34
a | 45 | 21:10:10
b | 3 | 23:45:00

现在我需要找到时间恰好大于给定输入的输入的名称和年龄。

假设我有一个输入 21:00:01,那么输出将为 21:10:10。我可以编写这个查询,但我有一个巨大的输入列表,每次我都无法对每个输入日期执行查询。

我需要的是一个查询,它将输入列表作为输入,并在下一次针对每个输入返回我。我被困在这里,请提供任何解决方案

当 ("21:00:01",...) 中有一个像 time in ("21:00:01",...) 这样的 where 子句时,我试图获得这样的输出

Name  |  age |     time  |    nexttime   |   nextname   |
------+------+-----------+---------------+---------------
x | 23 | 21:00:01 | 21:10:10 | a
y | 67 | 23:34:43 | 23:45:00 | b
z | 90 | 12:45:34 | 21:00:01 | x
a | 45 | 21:10:10 | 23:34:43 | y
b | 3 | 23:45:00 | |

最佳答案

将输入放入表中,例如InputTimes。然后您可以将其作为相关子查询来执行:

select it.*,
(select name
from table t
where t.time > it.time -- removed =
order by t.time
limit 1
) as name,
(select age
from table t
where t.time > it.time -- removed =
order by t.time
limit 1
) as age
from InputTimes it;

关于mysql - 从表中获取一组输入的下一个最大时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27060723/

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