Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using MONTH or DAY instead of YEAR.
Forgetting the FROM keyword.
✗ Incorrect
The EXTRACT function with YEAR extracts the year part from a date.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using YEAR or DAY instead of MONTH.
Missing the FROM keyword.
✗ Incorrect
Use EXTRACT(MONTH FROM ...) to get the month number from a date.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the FROM keyword.
Putting FROM before the unit.
✗ Incorrect
The correct syntax is EXTRACT(DAY FROM date_column). The FROM keyword must come after the unit.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping YEAR and MONTH.
Using DAY or HOUR instead of MONTH.
✗ Incorrect
Use YEAR to extract the year and MONTH to extract the month from a date.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of YEAR, MONTH, and DAY.
Using HOUR instead of DAY.
✗ Incorrect
Use YEAR, MONTH, and DAY in that order to extract each part from the date.