mysql - SQL,select语句如何在相关子查询中运行
问题描述
我试图理解以下代码。我认为第一个子查询将创建一个包含 2、3、4、5、6 的表。对于第二个子查询,我认为它将按如下方式运行。例如,@divisor 的初始值为 1,对于 nn=2,@num2<=nn 的条件有效,则执行 select 语句,则 @divisor 为 2。由于 where 条件仍然有效,再次运行select语句,使@divisor的值为3。此时where条件无效,select语句将停止。
基于这样的理解,我认为代码的结果应该是2,3,4,5,6,@divisor的最终值为6。但是,当我在mysql中运行代码时,结果为null。没有记录。
有人可以帮我吗?非常感谢。
set @num:=2;
set @num2:=1;
select nn from
(select @num:=@num+1 as nn from
information_schema.tables t1, information_schema.tables t2
where @num<=5) a
where nn in
(select @num2:=@num2+1 from
information_schema.tables t3, information_schema.tables t4
where @num2<=nn)
解决方案
推荐阅读
- multithreading - Jmeter将线程数作为动态值传递
- java - 为什么使用 set = map.entryset(); 时不必初始化集合?
- parse-platform - 使用 graphql 对解析服务器挂载的 POST 请求返回 400 Bad Request
- sql - 如何从异步 gcloud sql 导出作业中获取退出状态或完成消息?
- spring-cloud-dataflow - SCDF 为部署的流应用程序设置用户提供的环境变量
- java - java.lang.RuntimeException:在 Google Play 商店中上传时执行 doInBackground() 时发生错误
- arrays - 连续插入遇到的三个 ID 的所有唯一组合
- spring-batch - 是否可以在批处理作业开始执行之前读取静态表数据并将数据用作批处理作业的元数据
- python - BeautifulSoup 中的分解()
- function - 将具有多个参数的函数映射到 Julia 中的每一行 Array