Your organization receives GPS pings from vehicles that include trip and event IDs and a time stamp. You want to calculate the time difference between each ping and flag the row as skipped if the time difference with the previous row is less than 60 seconds.
You order the events chronologically and partition the events by trip. You define a window function that accesses the event time from the previous row, and you use an ADD_TO_DATE function to calculate the time difference between the two events.
Window properties
Property
Value
Description
Frame
Not specified
Window functions access rows based on the offset argument and ignore the frame.
Partition key
trip_id
Groups the rows according to trip ID so that calculations are based on events from the same trip.
Order key
_event_id Ascending
Arranges the data chronologically by ascending event ID.
Window function
You define the following LAG function to get the event time from the previous row:
LAG ( _event_time, 1, NULL )
For more information about the LAG function, see Function Reference.
You define the following DATE_DIFF function to calculate the length of time between the two dates: