代码拉取完成,页面将自动刷新
# $1767. 寻找没有被执行的任务对
# https://leetcode-cn.com/problems/find-the-subtasks-that-did-not-execute/
# SQL架构
Create table If Not Exists Tasks (task_id int, subtasks_count int);
Create table If Not Exists Executed (task_id int, subtask_id int);
Truncate table Tasks;
insert into Tasks (task_id, subtasks_count) values ('1', '3');
insert into Tasks (task_id, subtasks_count) values ('2', '2');
insert into Tasks (task_id, subtasks_count) values ('3', '4');
Truncate table Executed;
insert into Executed (task_id, subtask_id) values ('1', '2');
insert into Executed (task_id, subtask_id) values ('3', '1');
insert into Executed (task_id, subtask_id) values ('3', '2');
insert into Executed (task_id, subtask_id) values ('3', '3');
insert into Executed (task_id, subtask_id) values ('3', '4');
# Write your MySQL query statement below
with recursive tmp(task_id, subtask_id) as (
select
task_id,
subtasks_count
from
Tasks
union
select
task_id,
(subtask_id -1) as subtasks_count
from
tmp
where
subtask_id >= 2
)
select
task_id,
subtask_id
from
tmp
where
(task_id, subtask_id) not in (
select
task_id,
subtask_id
from
Executed
);
# clean-up
drop table Tasks;
drop table Executed;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。