-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVIEW_BahnhofTimetable.sql
More file actions
30 lines (25 loc) · 1.04 KB
/
VIEW_BahnhofTimetable.sql
File metadata and controls
30 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--*********************************************************************
--**
--** Table: Bahnhof_Timetable
--** Developer: Samuel Fiedorowicz
--** Description: View that show the timetable of every arrival and
--** departure of a train with the repsective trainstation
--** name and platform.
--**
--*********************************************************************
CREATE OR REPLACE
VIEW bahnhof_timetable AS
SELECT bh.bahnhofID, bh.bezeichnung AS name, bs.bezeichnung AS bahnsteig, v.fk_zugID AS zugID, v.abfahrt_uhrzeit AS Uhrzeit, 'Ankunft' AS verbindungTyp
FROM bahnsteig bs
JOIN bahnhof bh
ON bs.fk_bahnhofID = bh.bahnhofID
JOIN verbindung v
ON v.fk_ankunft_bahnsteig = bs.bahnsteigID
UNION
SELECT bh.bahnhofID, bh.bezeichnung AS name, bs.bezeichnung AS bahnsteig, v.fk_zugID AS zugID, v.abfahrt_uhrzeit AS uhrzeit, 'Abfahrt' AS verbindungTyp
FROM bahnsteig bs
JOIN bahnhof bh
ON bs.fk_bahnhofID = bh.bahnhofID
JOIN verbindung v
ON v.fk_abfahrt_bahnsteig = bs.bahnsteigID
ORDER BY uhrzeit ASC;