0
0
SQLquery~10 mins

YEAR, MONTH, DAY extraction in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extract the year from the date column.

SQL
SELECT [1](order_date) AS order_year FROM orders;
Drag options to blanks, or click blank then click option'
AYEAR
BMONTH
CDAY
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using MONTH() or DAY() instead of YEAR() will extract the wrong part.
Using DATE() is not a valid function to extract year.
2fill in blank
medium

Complete the code to extract the month from the date column.

SQL
SELECT [1](order_date) AS order_month FROM orders;
Drag options to blanks, or click blank then click option'
ADAY
BHOUR
CYEAR
DMONTH
Attempts:
3 left
💡 Hint
Common Mistakes
Using DAY() or YEAR() instead of MONTH() will give wrong results.
Using HOUR() is unrelated to date extraction.
3fill in blank
hard

Fix the error in the code to extract the day from the date column.

SQL
SELECT [1](order_date) AS order_day FROM orders;
Drag options to blanks, or click blank then click option'
AMONTH
BDAY
CYEAR
DDATEPART
Attempts:
3 left
💡 Hint
Common Mistakes
Using MONTH() or YEAR() instead of DAY() will extract the wrong part.
DATEPART() requires additional arguments and is not used here.
4fill in blank
hard

Fill both blanks to extract year and month from the date column.

SQL
SELECT [1](order_date) AS year, [2](order_date) AS month FROM orders;
Drag options to blanks, or click blank then click option'
AYEAR
BDAY
CMONTH
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping YEAR() and MONTH() functions.
Using DAY() or DATE() instead of MONTH() for the month extraction.
5fill in blank
hard

Fill all three blanks to extract year, month, and day from the date column.

SQL
SELECT [1](order_date) AS year, [2](order_date) AS month, [3](order_date) AS day FROM orders;
Drag options to blanks, or click blank then click option'
AYEAR
BMONTH
CDAY
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATE() instead of DAY() for the day extraction.
Mixing up the order of MONTH() and DAY() functions.