sql语句实现公交一次换乘,因为不会存储过程是怎么操作的,能否用sql关联方式实现

2025-03-24 06:46:26
推荐回答(1个)
回答1:

这个比较烦,应该还是可以做的:
(不换乘的结果)
select a.route_id, NULL, a.route_id
from route_station a
where 1 in (select station_id from a)
and 8 in (select station_id from a);

换乘一次:
select a.route_id,a.station_id, b.route_id
from route_station a, route_station b
where a.route_id<>b.route_id and a.station_id=b.station_id
and 1 in (select station_id from a) and 8 in (select station_id from b)

 换乘两次的按照换乘一次的扩展一下应该不难。