開始使用免費開始

統一航班格式 II

在上一個練習中,你使用了 CONCAT()REPLICATE()LEN()。你從 flight_statistics 資料表中,擷取了延誤次數超過 100 的所有登錄紀錄。你在一個獨立欄位中,將 carrier_coderegistration_codeairport_code 串接成類似這樣的格式:"AA - 0000119, JFK"

在本練習中,你會用另一種方式解同樣的題目,這次改用 FORMAT() 搭配 CONCAT() 一起完成。

本練習屬於課程

在 SQL Server 資料庫中清理資料

檢視課程

練習說明

  • 使用合適的函式,將 carrier_code、格式化後的 registration_code,以及 airport_code 串接在一起。
  • 在將 registration_code 轉型為整數的同時,套用格式化。
  • 篩選延誤次數超過 100 的登錄紀錄。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

SELECT 
    -- Concat the strings
	___(
		carrier_code, 
		' - ', 
        -- Format the code
		___(___(registration_code AS INT), '0000000'),
		', ', 
		airport_code
	) AS registration_code
FROM flight_statistics
-- Filter registers with more than 100 delays
WHERE ___ > 100
編輯並執行程式碼