當前位置:首頁 » 編程語言 » SQL中轉

SQL中轉

發布時間: 2023-02-06 00:40:51

❶ 簡單的列車中轉查詢演算法設計,SQL代碼或者思路也可以!

你這個表設計的真夠不合理的...
t_che表基本沒什麼用處

A->B
select* from t_zhan a
inner join t_zhan b on a.checi=b.checi
where a.zhan=A and b.zhan=B

A->B中轉
因為你中轉站無法確定 要查詢所有可能車次 需要看所有站點
select * from (
-- 所有經過A的車會經過的所有站
select checi,zhan from t_zhan where checi in(
--所有經過A的車
select checi from t_zhan where checi=A))a
inner join(
-- 所有經過B的車會經過的所有站
select checi,zhan from t_zhan where checi in(
--所有經過B的車
select checi from t_zhan where checi=B)) b
on a.zhan =b.zhan -- 站有交集的表示可以該站中轉

可以找出所有中轉車 但是無法保證乘坐站數最少

熱點內容
android設置不能點擊 發布:2025-09-17 11:54:50 瀏覽:658
共享電腦提示伺服器內存不足 發布:2025-09-17 11:33:17 瀏覽:634
python微信公眾號 發布:2025-09-17 11:13:10 瀏覽:547
源碼和千鋒 發布:2025-09-17 10:58:53 瀏覽:29
memcache資料庫 發布:2025-09-17 10:23:01 瀏覽:70
安卓機如何鎖軟體 發布:2025-09-17 10:18:34 瀏覽:948
二手3系買哪個配置好 發布:2025-09-17 10:07:16 瀏覽:745
sqlserver2000xp 發布:2025-09-17 09:36:19 瀏覽:834
c9什麼時候升級安卓70 發布:2025-09-17 09:35:36 瀏覽:216
速演算法中 發布:2025-09-17 09:30:50 瀏覽:385