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

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

熱點內容
嵌入式linuxc編程入門 發布:2025-09-16 08:24:18 瀏覽:371
碼片編程器 發布:2025-09-16 08:24:08 瀏覽:940
原神各畫質要什麼配置 發布:2025-09-16 08:17:32 瀏覽:309
讀取資料庫生成xml 發布:2025-09-16 08:17:19 瀏覽:786
sql2000開發版 發布:2025-09-16 07:56:31 瀏覽:795
linux桌面哪個 發布:2025-09-16 07:55:35 瀏覽:49
python讀取網頁 發布:2025-09-16 07:45:05 瀏覽:332
qq郵件的密碼是什麼 發布:2025-09-16 07:44:20 瀏覽:719
演算法什麼特點 發布:2025-09-16 07:40:10 瀏覽:348
matlab編程第四版答案 發布:2025-09-16 07:35:51 瀏覽:453