Advertisement
marcelopaixaoresende

workforce_query

Jan 2nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select
  2.     *,
  3.     case
  4.         when (x.direction != x.next_row_direction or x.next_row_direction is null)
  5.             then extract(EPOCH from x.duration) * 1000
  6.         else 0
  7.     end as real_difference
  8. from (
  9. select
  10.     workforce_entry.id,
  11.     workforce_entry_direction.description,
  12.     workforce_entry.workforce_entry_direction_id as direction,
  13.     lead(workforce_entry_direction_id, 1, null) over (partition by person_id order by date_time) as next_row_direction,
  14.     (lead(date_time, 1, now()) over (partition by person_id order by date_time) - workforce_entry.date_time)  as duration
  15. from workforce_entry
  16. inner join workforce_entry_direction
  17.     on workforce_entry_direction.id =  workforce_entry.workforce_entry_direction_id
  18. ) as x
  19. where x.description = 'IN';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement