1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1767.test 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
# $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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助