0
联合查询如何工作?内部查询是否根据外部查询行进行迭代?假设我的学生桌只有1个ID列,其中的值为1,2,3。任何人都可以给出图例吗?Oracle相关查询?
select count(*)
from student s where s.sid < any (select s1.id from student s1 where s1.id < s.id);
联合查询如何工作?内部查询是否根据外部查询行进行迭代?假设我的学生桌只有1个ID列,其中的值为1,2,3。任何人都可以给出图例吗?Oracle相关查询?
select count(*)
from student s where s.sid < any (select s1.id from student s1 where s1.id < s.id);
相关的子查询是(理论上 - 没有考虑可能的优化)对主表的每一行执行一次。
对于s.ID = 1个查询没有返回行(s1.ID < 1返回任何操作)
为s.ID = 2则返回1和(谓词s1.id < 2)
为s.ID = 3它返回1,2-
因此,第一行(s.ID = 1)没有被选择(子查询返回任何行),
第二行(一个或多个.ID = 2)谓词是s.id < any (1)
,它被重写为为ANY 请参阅规则和没有选择的行为2 < 1是FALSE
用于第三行(s.ID = 3)的谓词是s.id < any (1,2)
这是改写到s.id < 1 OR s.id < 2
这是FLASE为好。
所以查询
create table student as
select rownum id from dual connect by level <= 3;
select *
from student s where s.id < any (select s1.id from student s1 where s1.id < s.id);
返回空结果(没有行)。