IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Functions for Manipulating Data in PostgreSQL

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

SELECT 
  -- Extract day of week from rental_date
  ___(___ ___ ___) AS dayofweek 
FROM rental 
LIMIT 100;
Modifica ed esegui il codice