I have a query running in Automation studio that times out. The dataViewSubscribers data extension contains 20 million users. Is there a way this can be optimised?
SELECT
ds.emailaddress
, case
when ds.dateJoined >= convert(date, getDate()-14) then 'New'
when o.eventDate >= convert(date, getDate()-90)
and ds.dateJoined < convert(date, getDate()-14) then 'Active'
when ds.dateJoined < convert(date, getDate()-14)
and ds.dateJoined >= convert(date, getDate()-90)
and o.eventdate IS NULL then 'Defining'
when ds.dateJoined < convert(date, getDate()-90)
and o.eventdate IS NULL then 'At Risk'
when ds.dateJoined < convert(date, getDate()-90)
and o.eventdate < convert(date, getDate()-90)
and o.eventdate !< convert(date, getDate()-90) then 'Inactive'
end AS EngagementDefinition
FROM DataviewSubscribers ds
outer apply (
select
max(o0.eventDate) eventDate
from _Open o0
where o0.subscriberid = ds.subscriberid
and o0.isunique = 1
) o where ds._customobjectKey % 6 = 0
when ds.dateJoined < convert(date, getDate()-90) and o.eventdate < convert(date, getDate()-90) then 'At Risk' when ds.dateJoined < convert(date, getDate()-90) and o.eventdate IS NULL then 'Inactive'