當前位置:首頁 » 編程語言 » 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-07-12 21:30:38 瀏覽:621
資料庫中包含 發布:2025-07-12 21:25:08 瀏覽:621
艦娘緩存系統 發布:2025-07-12 21:21:21 瀏覽:100
cpu對存儲器的讀寫 發布:2025-07-12 21:21:14 瀏覽:772
如何建立一個網站需要伺服器 發布:2025-07-12 21:18:40 瀏覽:67
php登陸微信 發布:2025-07-12 21:17:55 瀏覽:14
公眾伺服器有什麼功能 發布:2025-07-12 21:11:22 瀏覽:715
健身的壓縮衣 發布:2025-07-12 21:11:12 瀏覽:754
磁碟伺服器如何管理磁碟 發布:2025-07-12 21:02:19 瀏覽:470
安卓返回鍵在哪裡取消 發布:2025-07-12 20:50:17 瀏覽:799