1. Învăţa
  2. /
  3. Courses
  4. /
  5. Functions for Manipulating Data in PostgreSQL

Connected

exercise

Using EXTRACT

You can use EXTRACT() and DATE_PART() to easily create new fields in your queries by extracting sub-fields from a source timestamp field.

Now suppose you want to produce a predictive model that will help forecast DVD rental activity by day of the week. You could use the EXTRACT() function with the dow field identifier in our query to create a new field called dayofweek as a sub-field of the rental_date column from the rental table.

You can COUNT() the number of records in the rental table for a given date range and aggregate by the newly created dayofweek column.

Instrucțiuni 1 / 2

undefined XP
    1
    2
  • Get the day of the week from the rental_date column.