CommencerCommencer gratuitement

Running total with lag

Each train line corresponds to a value of train_id. For each stop of the line for each line, calculate how long it takes for the train to travel from the previous stop to the current stop. Then, sum this over each line to obtain the amount of time it takes for the train to travel from the head of the line to each stop along the way.

Cet exercice fait partie du cours

Time Series Analysis in PostgreSQL

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

-- Fetch the previous arrival time 
SELECT
  train_id,
  station,
  arrival_time,
  ___ ___ (
	___
	ORDER BY arrival_time) AS previous_arrival_time
FROM train_schedule
ORDER BY train_id, arrival_time;
Modifier et exécuter le code