0
0
PostgreSQLquery~10 mins

EXTRACT function for date parts in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extract the year from the date column.

PostgreSQL
SELECT EXTRACT([1] FROM order_date) AS year FROM orders;
Drag options to blanks, or click blank then click option'
Ayear
Bmonth
Cday
Dhour
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'month' or 'day' instead of 'year' will extract the wrong part.
Forgetting to use EXTRACT syntax correctly.
2fill in blank
medium

Complete the code to extract the month from the timestamp column.

PostgreSQL
SELECT EXTRACT([1] FROM created_at) AS month FROM users;
Drag options to blanks, or click blank then click option'
Aday
Bminute
Cmonth
Dyear
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'day' or 'year' will give wrong results.
Not using EXTRACT function properly.
3fill in blank
hard

Fix the error in the code to correctly extract the day from the date column.

PostgreSQL
SELECT EXTRACT([1] FROM order_date) AS day FROM orders;
Drag options to blanks, or click blank then click option'
Aday
Bday_of_month
Cdate
Ddays
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural 'days' instead of 'day'.
Using 'date' which is not a valid part for EXTRACT.
4fill in blank
hard

Fill both blanks to extract the hour and minute from the timestamp column.

PostgreSQL
SELECT EXTRACT([1] FROM login_time) AS hour, EXTRACT([2] FROM login_time) AS minute FROM sessions;
Drag options to blanks, or click blank then click option'
Ahour
Bminute
Csecond
Dday
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up hour and minute keywords.
Using invalid parts like 'day' or 'second' for these blanks.
5fill in blank
hard

Fill all three blanks to extract year, month, and day from the birth_date column.

PostgreSQL
SELECT EXTRACT([1] FROM birth_date) AS year, EXTRACT([2] FROM birth_date) AS month, EXTRACT([3] FROM birth_date) AS day FROM people;
Drag options to blanks, or click blank then click option'
Ayear
Bmonth
Cday
Dhour
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hour' instead of 'day' for the last blank.
Mixing the order of year, month, and day.