1. Learn
  2. /
  3. Courses
  4. /
  5. Time Series Analysis in PostgreSQL

Exercise

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.

Instructions 1/3

undefined XP
    1
    2
    3
  • Fetch the previous arrival_time from the previous stop, partitioning by train_id.