當前位置:首頁 » 編程語言 » 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 -- 站有交集的表示可以該站中轉

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

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:538
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:826
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:528
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:711
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:632
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:944
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:200
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:61
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:754
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:656