gpt4 book ai didi

php - MYSQL 在午夜订购火车时刻表 PHP

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

我想按从车站出发的时间来排序火车时刻表,但当火车在午夜经过时出现问题。

下面是一个数据流入我的 mysql 数据库的例子。对于给定的火车时刻表,我有它的基本路线和每个车站的基本出发时间(在 sche 下用 y 标记)。时不时地,我可能还会收到给定火车时刻表的修改后出发时间的更新。

就其本身而言,上述内容不是问题,因为我根据 timeref 对数据进行排序。然而,当火车午夜经过时,我的问题就来了。这是因为我收到的时间是纯 24 小时格式 - 即 01:00

Count   Location       Trainid      Timeref     Sche     Update

1 London t256 22:10 y
2 Cricklewood t256 23:00 y
3 Luton t256 01:00 y
4 Leicester t256 02:00 y
5 Doncaster r659 06:00 y
6 Luton t256 01:10 y
7 Sheffield y783 05:00 y

我想显示如下数据(按顺序)。即按照原始时间表的顺序,但卢顿的更新时间为 01:10

 London        t256      22:10
Cricklewood t256 23:00
Luton t256 01:10
Leicester t256 02:00

我下面的代码工作正常,除了火车午夜经过的地方

 $stmt3=$mysql_link->prepare("SELECT count,trainid,location,timeref,sche,update FROM (SELECT count,trainid,location,timeref,sche,update FROM darwinall WHERE trainid=:trainid ORDER BY count DESC) as temp GROUP BY location ORDER BY timeref ASC");
$stmt3->execute(array(':trainid'=>$trainid));
foreach($stmt3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
echo result.................
}

所以我得到的不是上面的结果,这是错误的

Luton         t256      01:10
Leicester t256 02:00
London t256 22:10
Cricklewood t256 23:00

最佳答案

如果你想把午夜到早上 6 点之间的所有时间都放在其他时间之后,你可以这样做:

ORDER BY timeref < '06:00', timeref

关于php - MYSQL 在午夜订购火车时刻表 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29863120/

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