開始使用免費開始

Interval 型別

INTERVAL 型別提供了很實用的工具,能對日期與時間型別進行運算。例如,假設店內租借政策規定 DVD 需在 3 天內歸還。我們可以把 rental 資料表中的 rental_date 加上 3 天的 INTERVAL,來計算該筆租借的 expected_return_date。接著再把這個結果與實際的 return_date 比較,以判斷 DVD 是否逾期歸還。

現在就在這個練習中試試看這個例子吧。

本練習屬於課程

在 PostgreSQL 操作資料的函式

檢視課程

練習說明

  • rental 資料表選出租借日期與歸還日期。
  • rental_date 上加上 3 天的 INTERVAL,計算預期的歸還日期。

動手互動練習

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

SELECT
 	-- Select the rental and return dates
	___,
	___,
 	-- Calculate the expected_return_date
	rental_date + ___ ___ AS expected_return_date
FROM rental;
編輯並執行程式碼