Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to format the date as 'Year-Month-Day'.
SQL
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date FROM orders;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong order of year, month, and day.
Using slashes instead of dashes.
Using time format codes instead of date.
✗ Incorrect
The format '%Y-%m-%d' outputs the date as Year-Month-Day, which matches the requirement.
2fill in blank
mediumComplete the code to extract the month from the date.
SQL
SELECT EXTRACT([1] FROM 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 instead of MONTH.
Using YEAR when month is needed.
Using HOUR which is for time, not date.
✗ Incorrect
EXTRACT(MONTH FROM date) returns the month part of the date.
3fill in blank
hardFix the error in the code to extract the year from the date.
SQL
SELECT EXTRACT(YEAR [1] order_date) AS order_year FROM orders; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the FROM keyword.
Using BY, IN, or ON instead of FROM.
✗ Incorrect
The correct syntax is EXTRACT(YEAR FROM date), so 'FROM' is required.
4fill in blank
hardFill both blanks to format the date as 'Month/Day/Year' and extract the day.
SQL
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date, EXTRACT([2] FROM order_date) AS day_part FROM orders;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format codes.
Extracting MONTH instead of DAY.
✗ Incorrect
The format '%m/%d/%Y' gives Month/Day/Year, and EXTRACT(DAY FROM date) extracts the day.
5fill in blank
hardFill all three blanks to format the date as 'Year.Month.Day', extract the year, and extract the month.
SQL
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date, EXTRACT([2] FROM order_date) AS year_part, EXTRACT([3] FROM order_date) AS month_part FROM orders;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format string.
Mixing up YEAR and MONTH in EXTRACT.
✗ Incorrect
The format '%Y.%m.%d' formats date as Year.Month.Day, EXTRACT(YEAR FROM date) extracts year, EXTRACT(MONTH FROM date) extracts month.