Guest User

Untitled

a guest
Dec 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. select
  2. i.institution_guid,
  3. j.job_guid,
  4. j.started_at,
  5. coalesce(j.finished_at, j.updated_at) as finished_at,
  6. j.status as final_status_type,
  7. jsc.final_event as final_event_type,
  8. coalesce(ceiling(date_part('second', coalesce(j.finished_at, j.updated_at) - j.started_at)), -1) as job_duration
  9. FROM
  10. jobs j
  11. inner join members m on j.member_id = m.id
  12. inner join institutions i on m.institution_id = i.id
  13. inner join (select job_id, max(event) as final_event from job_status_changes group by job_id, event) jsc on jsc.job_id = j.id
  14. where
  15. (j.finished_at is not null or j.updated_at is not null)
  16. and jsc.final_event in (3,4,5,6,7,8,9)
  17. order by job_duration;
Add Comment
Please, Sign In to add comment