从 table 中获得正确的结果
Get the right result from the table
我有两个 table stops
和 arrivaletimes
如果找到但没有找到与 stop_id 相关的 route
像现在这样的路线。例如,如果找到停靠点 ABC
,我想根据当前时间获取此 stop_id 的路线。
查询结果:
SELECT route from arrivaltimes INNER JOIN stops ON
arrivaltimes.stop_id=stops.stop_id WHERE
time_format(arrivaltime,'%H:%i')= time_format(curtime() ,'%H:%i')
但我只想得到路线 1
作为结果,而不是与 stop_id
相关的所有路线
PFB 更正查询位置:
SELECT
route FROM arrivaltimes
INNER JOIN
stops ON arrivaltimes.stop_id = stops.stop_id
INNER JOIN
stops ON arrivaltimes.location = stops.location
WHERE
time_format(arrivaltime,'%H:%i') = time_format(curtime() ,'%H:%i')
ORDER BY
arrivaltimes.stop_id DESC LIMIT 1;
让我们知道结果。
我有两个 table stops
和 arrivaletimes
如果找到但没有找到与 stop_id 相关的 route
像现在这样的路线。例如,如果找到停靠点 ABC
,我想根据当前时间获取此 stop_id 的路线。
查询结果:
SELECT route from arrivaltimes INNER JOIN stops ON
arrivaltimes.stop_id=stops.stop_id WHERE
time_format(arrivaltime,'%H:%i')= time_format(curtime() ,'%H:%i')
但我只想得到路线 1
作为结果,而不是与 stop_id
PFB 更正查询位置:
SELECT
route FROM arrivaltimes
INNER JOIN
stops ON arrivaltimes.stop_id = stops.stop_id
INNER JOIN
stops ON arrivaltimes.location = stops.location
WHERE
time_format(arrivaltime,'%H:%i') = time_format(curtime() ,'%H:%i')
ORDER BY
arrivaltimes.stop_id DESC LIMIT 1;
让我们知道结果。