with recursive CTE as
(
SELECT task_id,subtasks_count,1 as result FROM Tasks
UNION ALL
SELECT CTE.task_id,subtasks_count,result+1 FROM CTE where result<subtasks_count
)
SELECT
CTE.task_id,CTE.result FROM CTE LEFT JOIN Executed e
on e.task_id=CTE.task_id and e.subtask_id= CTE.result
where e.subtask_id is null
order by task_id,result