Challenge - 5 Problems
Date Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this DATE_ADD query?
Given the table events with a column
event_date of type DATE, what will be the result of this query?SELECT DATE_ADD('2024-06-15', INTERVAL 10 DAY) AS new_date;MySQL
SELECT DATE_ADD('2024-06-15', INTERVAL 10 DAY) AS new_date;
Attempts:
2 left
💡 Hint
Think about adding 10 days to June 15, 2024.
✗ Incorrect
DATE_ADD adds the specified interval to the date. Adding 10 days to June 15, 2024 results in June 25, 2024.
❓ query_result
intermediate2:00remaining
What does this DATE_SUB query return?
Consider the query:
What is the output?
SELECT DATE_SUB('2024-01-01', INTERVAL 1 MONTH) AS previous_month;What is the output?
MySQL
SELECT DATE_SUB('2024-01-01', INTERVAL 1 MONTH) AS previous_month;
Attempts:
2 left
💡 Hint
Subtracting one month from January 1, 2024 goes to December 2023. Check the day part carefully.
✗ Incorrect
DATE_SUB subtracts the interval. Subtracting 1 month from January 1, 2024 results in December 1, 2023.
📝 Syntax
advanced2:00remaining
Which query correctly adds 2 hours to a datetime value?
You want to add 2 hours to the datetime '2024-06-15 10:00:00'. Which of these queries is syntactically correct and returns the expected result?
Attempts:
2 left
💡 Hint
Check the syntax for INTERVAL and the unit name.
✗ Incorrect
The correct syntax uses INTERVAL followed by a number and a singular unit name without quotes. Option A is correct. Options A, B, and D have syntax errors.
❓ optimization
advanced2:00remaining
Optimizing date subtraction in a WHERE clause
You want to select all records from
orders where order_date is within the last 30 days. Which query is the most efficient?Attempts:
2 left
💡 Hint
Think about how indexes work with functions on columns.
✗ Incorrect
Applying functions on columns (like DATE_SUB(order_date, ...)) prevents index use. Option A compares the column directly to a calculated constant, allowing index use and better performance.
🧠 Conceptual
expert2:00remaining
What is the result of this complex date arithmetic?
Consider this query:
What is the value of
SELECT DATE_ADD(DATE_SUB('2024-03-31', INTERVAL 1 MONTH), INTERVAL 1 MONTH) AS result_date;What is the value of
result_date?MySQL
SELECT DATE_ADD(DATE_SUB('2024-03-31', INTERVAL 1 MONTH), INTERVAL 1 MONTH) AS result_date;
Attempts:
2 left
💡 Hint
Subtracting one month from March 31, 2024, then adding one month back may not return the original date.
✗ Incorrect
DATE_SUB('2024-03-31', INTERVAL 1 MONTH) results in '2024-02-29' (leap year). Adding one month to '2024-02-29' results in '2024-03-29'.