2015-05-19 36 views
0

我想根據公交車的位置和到達時間從routesarrivaltimes表中獲取路線編號。我有3個表route,stops,arrivaltime。在到達時間表stop_id中,止損表route_id也是外鍵。這對我目前的數據庫設計是否可行?我如何查詢?根據位置和到達時間查找路線

我不知道添加了路由表來定義停靠點的路由順序。我使用harvsin公式來計算距離。

我很感激任何幫助。

enter image description here

enter image description here

enter image description here

+0

順便說一句,考慮將週一至週日當作位整數,其中1 =「星期一」,2 =「星期二',4 ='星期三',8 ='星期四'和127 =每天。沒有圖片,請。恰當的DDL – Strawberry

回答

1

加入基於緯度,隆基和arrivaltime基於該stop_id列的stopstable和過濾你的arrivaltimes_table。例如:

select a.route 
from arrivaltimes_table a 
join stopstable s on a.stop_id = s.stop_id 
where s.lat = 53.868937 
and s.longi = 10.665545 
and a.arrivaltime = '12:25:00'; 

如果你想ROUTE_ID而是使用select s.route_id應該返回路線1。如果您只想查看特定日期,請在a.weekday列中過濾。例如,發現,在上週日特定時間停在一個特定位置的路線:

select a.route 
from arrivaltimes_table a 
join stopstable s on a.stop_id = s.stop_id 
where s.lat = 53.868937 
and s.longi = 10.665545 
and a.weekday = 'sun' 
and a.arrivaltime = '12:25:00'; 
+0

答案中的「a」是什麼?我怎樣才能找到方向? –

+0

Ok'a'是arrivaltimes表 –

+0

'選擇從arrivaltimes arrivaltimes.route 上arrivaltimes.stop_id = stops.stop_id 其中stops.lat = 53.868937 和stops.longi = 10.665545 和arrivaltimes.arrivaltime = '12加入停止:25:00' ;'但我得到這些路由'1 31' –

相關問題