BIP – Query to extract count of persons without Primary email address
SELECT COUNT(DISTINCT pea.person_id)
FROM per_email_Addresses pea
WHERE pea.email_type = 'W1'
AND NOT EXISTS (select 1 from per_all_people_f papf
where papf.primary_email_id = pea.email_address_id)
Below is the query to find active employees without primary email address:
SELECT 'Total Employees without Primary Work Email ', COUNT(DISTINCT pea.person_id)
FROM per_email_Addresses pea
WHERE pea.email_type = 'W1'
AND NOT EXISTS (select 1 from per_all_people_f papf
where papf.primary_email_id = pea.email_address_id)
UNION
SELECT 'Active Employees without Primary Work Email ', COUNT(DISTINCT pea.person_id)
FROM per_email_Addresses pea
WHERE pea.email_type = 'W1'
AND NOT EXISTS (select 1 from per_all_people_f papf
where papf.primary_email_id = pea.email_address_id)
AND EXISTS (SELECt 1 from per_all_assignments_m paam
where assignment_type ='E'
and trunc(sysdate) between effective_start_date and effective_end_date
and paam.person_id = pea.person_id
and paam.assignment_status_type like 'ACTIVE%')