获取所有可能的机场
接下来的两个练习将搜索所有可能的航线。也就是说,首先,您需要从表 flightPlan 中找出所有可能的出发和目的地机场。
在本练习中,您将使用 UNION 语法创建名为 possible_Airports 的 CTE 表,其中包含所有可能的机场。UNION 的第一个查询选择 Departure 机场,第二个查询选择 Arrival 机场。
本练习是课程的一部分
SQL Server 中的分层与递归查询
练习说明
- 定义 CTE 表
possible_Airports,并包含字段Airports。 - 通过合并
Departure与Arrival机场来选择机场。 - 使用正确的语句将出发机场与目的地机场合并。
- 从
possible_Airports中选择所有可能的Airports。
交互式实操练习
通过完成这段示例代码来试试这个练习。
-- Definition of the CTE table
___ possible_Airports (___) ___(
-- Select the departure airports
SELECT ___
FROM flightPlan
-- Combine the two queries
___
-- Select the destination airports
SELECT ___
FROM flightPlan)
-- Get the airports from the CTE table
SELECT ___
FROM ___;