Challenge - 5 Problems
Date and Time 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 query?
Consider the table events with a column
event_date of type DATE. What will this query return?SELECT event_date + INTERVAL 1 DAY AS next_day FROM events WHERE event_date = '2024-06-15';MySQL
SELECT event_date + INTERVAL 1 DAY AS next_day FROM events WHERE event_date = '2024-06-15';
Attempts:
2 left
💡 Hint
Think about how MySQL adds intervals to date values.
✗ Incorrect
In MySQL, adding INTERVAL 1 DAY to a DATE value returns the date one day later. So the query returns dates that are one day after '2024-06-15' for matching rows.
🧠 Conceptual
intermediate1:30remaining
Which MySQL data type stores both date and time?
You want to store a value that includes both the date and the time of an event. Which MySQL data type should you use?
Attempts:
2 left
💡 Hint
Think about which type includes both parts, date and time.
✗ Incorrect
The DATETIME type stores both date and time values together, unlike DATE (date only) or TIME (time only). YEAR stores only the year part.
📝 Syntax
advanced2:00remaining
Which query correctly extracts the year from a DATETIME column?
Given a table
orders with a created_at column of type DATETIME, which query correctly returns the year part of created_at?Attempts:
2 left
💡 Hint
MySQL has a built-in function named YEAR().
✗ Incorrect
In MySQL, YEAR() extracts the year from a date or datetime value. EXTRACT() syntax is valid but requires different format. DATEPART() and ->year are not valid in MySQL.
❓ optimization
advanced2:30remaining
How to optimize a query filtering by date only on a DATETIME column?
You have a large table
logs with a created_at DATETIME column. You want to find all rows from '2024-06-01' ignoring time. Which query is optimized for using an index on created_at?Attempts:
2 left
💡 Hint
Functions on columns can prevent index use.
✗ Incorrect
Using a range condition on the column (option B) allows MySQL to use an index efficiently. Using DATE() function or LIKE on the column disables index usage. BETWEEN with '23:59:59' can miss some times with fractional seconds.
🔧 Debug
expert3:00remaining
Why does this query return no rows?
Given a table
appointments with a start_time column of type TIME, why does this query return no rows?SELECT * FROM appointments WHERE start_time = '09:00';MySQL
SELECT * FROM appointments WHERE start_time = '09:00';
Attempts:
2 left
💡 Hint
Check the format expected for TIME values in MySQL.
✗ Incorrect
MySQL TIME values expect 'HH:MM:SS' format. '09:00' lacks seconds, so it does not match any TIME value stored with seconds like '09:00:30'.