В вашем внутреннем подзапросе вы используете вложенный подзапрос с агрегированным результатом для возврата значений в предложение IN ..
вам следует избегать этого, используя соединение
select a11.sub_grp_nm AS Sub_Group_nm,
a11.grp_nm AS Group_nm,
sum(CASE WHEN a11.mnth_id = max_mnth - 100 THEN a11.scr_val ELSE NULL END) AS metric1,
max(CASE WHEN a11.mnth_id = max_mnth - 100 THEN 1 ELSE 0 END) AS flag1,
sum(CASE WHEN a11.mnth_id = max_mnth - 2 THEN a11.scr_val ELSE NULL END) AS metric2,
max(CASE WHEN a11.mnth_id = max_mnth - 2 THEN 1 ELSE 0 END) AS flag2,
sum(CASE WHEN a11.mnth_id = max_mnth - 1 THEN a11.scr_val ELSE NULL END) AS metric3,
max(CASE WHEN a11.mnth_id = max_mnth - 1 THEN 1 ELSE 0 END) AS flag3,
sum(a11.mnth_over_mnth_scr_val) AS metric4,
sum(a11.yr_over_yr_scr_val) AS metric5
from summary_table a11
INNER JOIN (
select summary_table.sub_grp_nm, summary_table.grp_nm, max(mnth_id) max_mnth
from summary_table
group by summary_table.sub_grp_nm, summary_table.grp_nm
) T ON T.sub_grp_nm = a11.sub_grp_nm, T.grp_nm = a11.grp_nm
например:
select pa14.Group_nm AS Group_nm,
pa14.Sub_Group_nm AS Sub_Group_nm,
pa14.metric1 AS metric1,
pa14.metric2 AS metric2,
pa14.metric3 AS metric3,
pa14.metric4 AS metric4,
pa14.metric5 AS metric5
from (
select a11.sub_grp_nm AS Sub_Group_nm,
a11.grp_nm AS Group_nm,
sum(CASE WHEN a11.mnth_id = max_mnth - 100 THEN a11.scr_val ELSE NULL END) AS metric1,
max(CASE WHEN a11.mnth_id = max_mnth - 100 THEN 1 ELSE 0 END) AS flag1,
sum(CASE WHEN a11.mnth_id = max_mnth - 2 THEN a11.scr_val ELSE NULL END) AS metric2,
max(CASE WHEN a11.mnth_id = max_mnth - 2 THEN 1 ELSE 0 END) AS flag2,
sum(CASE WHEN a11.mnth_id = max_mnth - 1 THEN a11.scr_val ELSE NULL END) AS metric3,
max(CASE WHEN a11.mnth_id = max_mnth - 1 THEN 1 ELSE 0 END) AS flag3,
sum(a11.mnth_over_mnth_scr_val) AS metric4,
sum(a11.yr_over_yr_scr_val) AS metric5
from summary_table a11
INNER JOIN (
select summary_table.sub_grp_nm, summary_table.grp_nm, max(mnth_id) max_mnth
from summary_table
group by summary_table.sub_grp_nm, summary_table.grp_nm
) T ON T.sub_grp_nm = a11.sub_grp_nm, T.grp_nm = a11.grp_nm
) pa14
where (pa14.flag1 = 1
and pa14.flag2 = 1
and pa14.flag3 = 1)