Task:
-
Never got a single process
select candidates.id as "CandidateId",
concat_ws(' ', candidates.first_name, candidates.last_name) as "CandidateName",
concat_ws(' ', consultants.first_name, consultants.last_name) as "ConsultantName",
date(to_timestamp(max(arhistory.created_at))) as "ActivatedAt",
string_agg(categories.name, ', ') as "CandidateCategory"
from candidates
left join consultants on candidates.consultants_id = consultants.id
left join arhistory on arhistory.row_id = candidates.id and arhistory.table_name = 'candidates'
left join candidates_categories on candidates.id = candidates_categories.candidates_id
left join categories on candidates_categories.categories_id = categories.id
where not exists(select 1
from candidates_vacancy_requests
where candidates_vacancy_requests.candidates_id = candidates.id)
and arhistory.field_name = 'status_id'
and arhistory.new_value = '5'
group by candidates.id, consultants.id
order by candidates.id;
-
Got their last process over 2 weeks ago (with no active processes)
select candidates.id as "CandidateId",
concat_ws(' ', candidates.first_name, candidates.last_name) as "CandidateName",
concat_ws(' ', consultants.first_name, consultants.last_name) as "ConsultantName",
date(to_timestamp(max(arhistory.created_at))) as "ActivatedAt",
string_agg(categories.name, ', ') as "CandidateCategory"
from candidates
left join consultants on candidates.consultants_id = consultants.id
left join arhistory on arhistory.row_id = candidates.id and arhistory.table_name = 'candidates'
left join candidates_categories on candidates.id = candidates_categories.candidates_id
left join categories on candidates_categories.categories_id = categories.id
where not exists(select 1
from candidates_vacancy_requests
where candidates_vacancy_requests.candidates_id = candidates.id
and candidates_vacancy_requests.status in (4, 11, 13, 14, 15, 19)
and (candidates_vacancy_requests.date_add) < '2023-01-04')
and not exists(select 1
from candidates_vacancy_requests
where candidates_vacancy_requests.candidates_id = candidates.id
and candidates_vacancy_requests.status not in (4, 11, 13, 14, 15, 19))
and arhistory.field_name = 'status_id'
and arhistory.new_value = '5'
group by candidates.id, consultants.id
order by candidates.id;
Leave a Reply
You must be logged in to post a comment.