Extracting Date Parts Using EXTRACT Function in PostgreSQL
📖 Scenario: You work for a company that stores employee information including their hire dates. You want to analyze the year and month when employees were hired.
🎯 Goal: Build a SQL query that extracts the year and month parts from employee hire dates using the EXTRACT function.
📋 What You'll Learn
Create a table called
employees with columns id (integer) and hire_date (date).Insert three employees with exact hire dates: 2019-04-15, 2020-11-30, and 2021-07-01.
Write a query that selects
id, the year part of hire_date as hire_year, and the month part of hire_date as hire_month using the EXTRACT function.Complete the query by ordering the results by
id ascending.💡 Why This Matters
🌍 Real World
Extracting parts of dates is common in reports, analytics, and filtering data by time periods.
💼 Career
Database developers and analysts often use EXTRACT to manipulate and analyze date and time data efficiently.
Progress0 / 4 steps