Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- *,
- case
- when (x.direction != x.next_row_direction or x.next_row_direction is null)
- then extract(EPOCH from x.duration) * 1000
- else 0
- end as real_difference
- from (
- select
- workforce_entry.id,
- workforce_entry_direction.description,
- workforce_entry.workforce_entry_direction_id as direction,
- lead(workforce_entry_direction_id, 1, null) over (partition by person_id order by date_time) as next_row_direction,
- (lead(date_time, 1, now()) over (partition by person_id order by date_time) - workforce_entry.date_time) as duration
- from workforce_entry
- inner join workforce_entry_direction
- on workforce_entry_direction.id = workforce_entry.workforce_entry_direction_id
- ) as x
- where x.description = 'IN';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement