with temp1 as (
select dbname, last_job_run_time_from_job_log, row_number() over (partition by dbname order by last_job_run_time_from_job_log desc) as rn
from --a bunch of already ridiculous subqueries and table valued udfs
where max(last_job_run_time_from_job_log) > SLA_job_run_time
)
select...