Aan de slagGa gratis aan de slag

Using DATE_TRUNC

The DATE_TRUNC() function will truncate timestamp or interval data types to return a timestamp or interval at a specified precision. The precision values are a subset of the field identifiers that can be used with the EXTRACT() and DATE_PART() functions. DATE_TRUNC() will return an interval or timestamp rather than a number. For example

SELECT DATE_TRUNC('month', TIMESTAMP '2005-05-21 15:30:30');

Result: 2005-05-01 00;00:00

Now, let's experiment with different precisions and ultimately modify the queries from the previous exercises to aggregate rental activity.

Deze oefening maakt deel uit van de cursus

Functions for Manipulating Data in PostgreSQL

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- Truncate rental_date by year
SELECT ___(___, ___) AS rental_year
FROM rental;
Code bewerken en uitvoeren