从日期中提取部分
在本练习中,您将练习使用 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;