เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Presenting parts of a date

DATENAME() and DATEPART() are two similar functions. The difference between them is that while the former understandably shows some date parts, as strings of characters, the latter returns only integer values.

In this exercise, you will use both of these functions to select the month and weekday of the first_vote_date in different forms.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Functions for Manipulating Data in SQL Server

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Extract the month number of the first vote.
  • Extract the month name of the first vote.
  • Extract the weekday number of the first vote.
  • Extract the weekday name of the first vote.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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;
แก้ไขและรันโค้ด