递归查询

递归查询

1767. 寻找没有被执行的任务队

# 递归查询
# 生成一个包含数字 1 到 20 的递增数列
WITH RECURSIVE NumberSeries AS (  # 表名 NumberSeries
  SELECT 1 AS number
  UNION ALL
  SELECT number + 1
  FROM NumberSeries
  WHERE number < 20
)
SELECT number FROM NumberSeries;  # 字段名:number

答案:

WITH RECURSIVE NumberSeries AS (
  SELECT 1 AS number
  UNION ALL
  SELECT number + 1
  FROM NumberSeries
  WHERE number < 20
)

select task_id, subtask_id from
(
    select task_id, number subtask_id from Tasks, NumberSeries where
    subtasks_count >= number) temp
    where (task_id, subtask_id) NOT IN
    (select task_id, subtask_id from Executed);

1613. 找到遗失的 ID

# Write your MySQL query statement below
WITH RECURSIVE NumberSeries as( # NumberSeries 表名
    select 1 as number  # number 列名
    union all
    select number + 1
    from  NumberSeries
    where number <= 100
)

select `number` ids from NumberSeries
    where `number` between 1 and (select max(customer_id) from Customers) and `number` not in (select customer_id from Customers)
posted @ 2023-12-22 18:48  爱新觉罗LQ  阅读(7)  评论(0编辑  收藏  举报