The EXTRACT function is used in SQL to retrieve specific parts of a date or time value, such as the year, month, or day.
It is useful for breaking down timestamps for reporting or filtering.
SELECT EXTRACT(part FROM date_column)
FROM table_name;partcan beYEAR,MONTH,DAY,HOUR,MINUTE,SECOND, etc.date_columnis the column containing the date or timestamp.
SELECT EXTRACT(YEAR FROM hire_date) AS hire_year
FROM employees;- This query extracts the year from each employee’s hire date.
- Common parts you can extract:
YEAR,MONTH,DAY,HOUR,MINUTE,SECOND. - Some databases (like MySQL) use functions like
YEAR(date_column)instead ofEXTRACT. EXTRACTworks with bothDATEandTIMESTAMPdata types.
SELECT EXTRACT(MONTH FROM order_date) AS order_month
FROM orders;- This query extracts the month from each order date.
Describe the problem, challenge, or topic discussed in a video related to SELECT FROM.
What concept was explained or what exercise was solved?
-- Write your SQL code attempt or solution related to SQL COMMAND
SQL COMMANDSQL COMMANDExplanation - Explain what you learned, any key takeaways, or how you solved the problem related to COMMAND._