0
0
MySQLquery~10 mins

EXTRACT and YEAR/MONTH/DAY in MySQL - 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.

MySQL
SELECT EXTRACT([1] FROM order_date) AS order_year FROM orders;
Drag options to blanks, or click blank then click option'
AHOUR
BMONTH
CYEAR
DDAY
Attempts:
3 left
💡 Hint
Common Mistakes
Using MONTH or DAY instead of YEAR.
Forgetting the FROM keyword.
2fill in blank
medium

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

MySQL
SELECT EXTRACT([1] FROM shipment_date) AS shipment_month FROM shipments;
Drag options to blanks, or click blank then click option'
ADAY
BMONTH
CYEAR
DMINUTE
Attempts:
3 left
💡 Hint
Common Mistakes
Using YEAR or DAY instead of MONTH.
Missing the FROM keyword.
3fill in blank
hard

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

MySQL
SELECT EXTRACT([1] FROM shipment_date) AS day_extracted FROM shipments;
Drag options to blanks, or click blank then click option'
ADAY
BFROM DAY
CDAY FROM
DMONTH FROM
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the FROM keyword.
Putting FROM before the unit.
4fill in blank
hard

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

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

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

MySQL
SELECT EXTRACT([1] FROM event_date) AS year, EXTRACT([2] FROM event_date) AS month, EXTRACT([3] FROM event_date) AS day FROM events;
Drag options to blanks, or click blank then click option'
ADAY
BMONTH
CYEAR
DHOUR
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of YEAR, MONTH, and DAY.
Using HOUR instead of DAY.