Leetcode Problem 1767. Find the Subtasks That Did Not Execute

1767. Find the Subtasks That Did Not Execute

Leetcode Solutions

Recursive Common Table Expression (CTE) and Anti-Join

  1. Create a recursive CTE that selects task_id and subtasks_count from the Tasks table.
  2. Add a recursive part to the CTE that selects task_id and subtasks_count - 1 as long as subtasks_count is greater than 1.
  3. Select task_id and subtasks_count as subtask_id from the CTE.
  4. Perform a LEFT JOIN with the Executed table on task_id and subtask_id.
  5. Use a WHERE clause to filter out rows where Executed.subtask_id is not NULL, which indicates that the subtask has not been executed.
  6. Return the result, which includes the task_id and the missing subtask_ids.

erDiagram
    Tasks {
        int task_id PK
        int subtasks_count
    }

    Executed {
        int task_id PK
        int subtask_id PK
    }

    Tasks ||--o{ Executed : "has"

Cross Join and Left Anti-Join

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...