展示日期的部分信息
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;