Skip to content

Commit d7cb5ed

Browse files
authored
Create 49-01767-find-the-subtasks-that-did-not-execute.sql
1 parent a8df0e9 commit d7cb5ed

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- using recursive CTE
2+
-- calculate subtask_count starting from given number, subtracting 1 till it reaches 1
3+
-- so subtasks count shouldn't be less than 2, because 2-1 = 1, and 1-1 will become 0
4+
-- use recursive cte to get all subtaks
5+
-- in the final query, pull all rows from cte, except the rows in Executed table
6+
7+
with recursive cte as
8+
(select task_id, subtasks_count
9+
from Tasks
10+
11+
union all
12+
13+
select task_id, subtasks_count-1
14+
from cte
15+
where subtasks_count > 1)
16+
17+
select task_id, subtasks_count as subtask_id
18+
from cte
19+
where (task_id, subtasks_count) not in (select *
20+
from Executed)
21+
22+
-- google- 1

0 commit comments

Comments
 (0)