I’ve a table data
For the same ER and month, if there’s no data for scenario budget_N or act_N, so no insertion in the final table:
This is what I think a good point to start
select *
FROM your_table
WHERE (ER, MONTH) IN (
SELECT ER, MONTH
FROM your_table
GROUP BY ER, MONTH
HAVING COUNT(CASE WHEN SCENARIO_CD = 'BUDGET_N' THEN 1 END) = 0
OR COUNT(CASE WHEN SCENARIO_CD = 'ACT_N' THEN 1 END) = 0
);