Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The YEAR() function extracts the year part from a date.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DAY() or YEAR() instead of MONTH() will give wrong results.
Using HOUR() is unrelated to date extraction.
✗ Incorrect
The MONTH() function extracts the month number from a date.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The DAY() function extracts the day number from a date.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping YEAR() and MONTH() functions.
Using DAY() or DATE() instead of MONTH() for the month extraction.
✗ Incorrect
Use YEAR() to get the year and MONTH() to get the month from a date.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATE() instead of DAY() for the day extraction.
Mixing up the order of MONTH() and DAY() functions.
✗ Incorrect
Use YEAR(), MONTH(), and DAY() functions to extract the respective parts from a date.