從日期擷取各部分
在這個練習中,你會用 SQL Server 的內建函式,從日期中擷取各個部分。這些函式很容易使用,而且也能在 WHERE 子句中使用,用來限制查詢回傳的結果。
你會先查詢 voters 資料表,並從 first_vote_date 擷取年份、月份與日期來建立新欄位。
本練習屬於課程
SQL Server 的資料操作函式
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
SELECT
first_name,
last_name,
-- Extract the year of the first vote
___ AS first_vote_year,
-- Extract the month of the first vote
___ AS first_vote_month,
-- Extract the day of the first vote
___ AS first_vote_day
FROM voters;