SQL 的理论基础是关系代数,而关系代数的主要操作只有 5 种,分别是并、差、积、选择、投影。所有的 SQL 语句最后都能用这 5 种操作组合完成。而一个嵌套子查询可以等价转换成一个连接(join)操作

select panthera_10.panthera_1 as s_grade from (select panthera_1, panthera_4, 
panthera_6, s_empname, s_city from (select s_grade as panthera_1, s_city as 
panthera_4, s_empname as panthera_6, s_empname as s_empname, s_city as 
s_city from staff) panthera_14 left outer join (select panthera_16.panthera_7 as 
panthera_7, panthera_16.panthera_8 as panthera_8, panthera_16.panthera_9 as 
panthera_9, panthera_16.panthera_12 as panthera_12, panthera_16.panthera_13 
as panthera_13 from (select panthera_0.panthera_1 as panthera_7, 
panthera_0.panthera_4 as panthera_8, panthera_0.panthera_6 as panthera_9, 
panthera_0.s_empname as panthera_12, panthera_0.s_city as panthera_13 from 
(select s_grade as panthera_1, s_city as panthera_4, s_empname as panthera_6, 
s_empname, s_city from staff) panthera_0 left semi join (select p_city as 
panthera_3, p_pname as panthera_5 from proj) panthera_2 on 
(panthera_0.panthera_4 = panthera_2.panthera_3) and (panthera_0.panthera_6 
= panthera_2.panthera_5) where true) panthera_16 group by 
panthera_16.panthera_7, panthera_16.panthera_8, panthera_16.panthera_9, 
panthera_16.panthera_12, panthera_16.panthera_13) panthera_15 on 
((((panthera_14.panthera_1 <=> panthera_15.panthera_7) and 
(panthera_14.panthera_4 <=> panthera_15.panthera_8)) and 
(panthera_14.panthera_6 <=> panthera_15.panthera_9)) and 
(panthera_14.s_empname <=> panthera_15.panthera_12)) and 
(panthera_14.s_city <=> panthera_15.panthera_13) where 
((((panthera_15.panthera_7 is null) and (panthera_15.panthera_8 is null)) and 
(panthera_15.panthera_9 is null)) and (panthera_15.panthera_12 is null)) and 
(panthera_15.panthera_13 is null)) panthera_10 ;

SQL 的理论基础是关系代数,而关系代数的主要操作只有 5 种,分别是并、差、积、选择、投影。所有的 SQL 语句最后都能用这 5 种操作组合完成。而一个嵌套子查询可以等价转换成一个连接(join)操作

posted @ 2022-06-26 17:30  DATA_MONK  阅读(1)  评论(0编辑  收藏  举报