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

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

熱點內容
怎麼設蘋果手機id密碼忘了怎麼辦 發布:2025-07-13 14:30:38 瀏覽:211
sqlintvarchar 發布:2025-07-13 14:20:13 瀏覽:310
linuxisthisok 發布:2025-07-13 14:12:13 瀏覽:161
sql查詢分析器下載 發布:2025-07-13 14:07:45 瀏覽:53
怎麼設置網路與計算機配置同步 發布:2025-07-13 14:01:39 瀏覽:450
jsp查詢資料庫顯示 發布:2025-07-13 14:01:37 瀏覽:191
winrar解壓慢 發布:2025-07-13 13:57:26 瀏覽:742
我的世界新手區伺服器 發布:2025-07-13 13:50:52 瀏覽:954
M視頻壓縮 發布:2025-07-13 13:50:04 瀏覽:211
潤享wifi密碼是多少 發布:2025-07-13 13:49:48 瀏覽:613