DROP VIEW
IF
	EXISTS v_TrainRoutes;
DROP VIEW
IF
	EXISTS v_StayTimes;
DROP VIEW
IF
	EXISTS v_TrainStationCounts;
CREATE VIEW v_TrainRoutes AS SELECT
ID AS TrainID,
StationID_start,
StationID_arrive 
FROM
	Trains;
CREATE VIEW v_StayTimes AS SELECT
TrainID,
StationID,
arrive_time,
leave_time,
TIMEDIFF( leave_time, arrive_time ) AS StayDuration 
FROM
	Passbys;
CREATE VIEW v_TrainStationCounts AS SELECT
TrainID,
COUNT( StationID ) AS StationCount 
FROM
	Passbys 
GROUP BY
	TrainID;
SELECT
	* 
FROM
	v_StayTimes 
WHERE
	TrainID = 'G103';
UPDATE v_StayTimes 
SET StationID = 3 
WHERE
	TrainID = 'G103' 
	AND arrive_time = '2024-03-28 07:13:00';
SELECT
	* 
FROM
	v_StayTimes 
WHERE
	TrainID = 'G103';
DELETE 
FROM
	v_StayTimes 
WHERE
	TrainID = 'G103' 
	AND arrive_time = '2024-03-28 07:13:00';
SELECT
	* 
FROM
	v_StayTimes 
WHERE
	TrainID = 'G103';