使用 CURRENT_TIMESTAMP
在分析型查詢中,另一個常見需求是找出相對於目前日期或時間的一段區間內的資料。雖然我們的資料日期都在過去,但你經常會處理每天更新,甚至是串流寫入的資料表。
本練習屬於課程
BigQuery 入門
練習說明
- 完成查詢,使用
DATE_DIFF()函式計算前 5 筆訂單相對於今天的天數差。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Finish the query to find the difference in days
SELECT
-- Add in the function to find the difference between two dates
___(
-- Finish the statement with the correct date part
EXTRACT(___ FROM order_purchase_timestamp),
-- Add the function to find the current date
___(),
DAY
)
FROM
ecommerce.ecomm_order_details
LIMIT 5;