開始使用免費開始

取得所有可能的機場

接下來兩個練習的任務是搜尋所有可能的航線。也就是說,你需要先從 flightPlan 資料表找出所有可能的起飛與目的地機場。

在這個練習中,你會使用 UNION 語法建立名為 possible_Airports 的 CTE,其中包含所有可能的機場。UNION 的第一個查詢選取 Departure 機場,第二個查詢選取 Arrival 機場。

本練習屬於課程

SQL Server 的階層式與遞迴查詢

檢視課程

練習說明

  • 定義 CTE 資料表 possible_Airports,並包含欄位 Airports
  • 透過結合 DepartureArrival 機場來選取機場清單。
  • 使用正確的敘述將起飛機場與目的地機場合併。
  • 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 ___;
編輯並執行程式碼