開始使用免費開始

呈現日期的各個部分

DATENAME()DATEPART() 是兩個相似的函式。差別在於,前者會以字串形式顯示部分日期欄位,而後者只會回傳整數值。

在這個練習中,你會同時使用這兩個函式,以不同的形式選取 first_vote_date 的月份與星期幾。

本練習屬於課程

SQL Server 的資料操作函式

檢視課程

練習說明

  • 擷取第一筆投票的月份數字。
  • 擷取第一筆投票的月份名稱。
  • 擷取第一筆投票的星期幾數字。
  • 擷取第一筆投票的星期幾名稱。

動手互動練習

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

SELECT 
	first_name,
	last_name,
   	-- Extract the month number of the first vote
	___(MONTH,___) AS first_vote_month1,
	-- Extract the month name of the first vote
    ___(MONTH,___) AS first_vote_month2,
	-- Extract the weekday number of the first vote
	___(WEEKDAY,___) AS first_vote_weekday1,
    -- Extract the weekday name of the first vote
	___(WEEKDAY,___) AS first_vote_weekday2
FROM voters;
編輯並執行程式碼