我不熟悉SQL。
我有公共汽车的时间表。主表bus_races有以下列:id、race_id、station_id和time。每一次公共汽车比赛都有每一站在途中的记录。
例如
id race station time
8132 1 1 05:31:00
8133 1 2 05:40:00
8134 1 4 05:50:00
8135 2 2 06:50:00
8136 2 4 06:55:00
8137 2 5 07:15:00这意味着1号公交线路有三个车站: 5.31站1站、5.40站2站、5.50站4站、6.50站2站、6.55站4站和7.15站。
..。等
如何构造一个查询,返回站2和站6上停止的所有比赛的race_id,站2必须早于站6。
发布于 2019-10-16 17:12:43
select a.race_id
from bus_races a join bus_races b
on a.race_id = b.race_id and a.station_id = 2 and b.station_id = 6
where a.time < b.timehttps://stackoverflow.com/questions/58418398
复制相似问题