Introduction
Dates
Time
Timestamps
Extract functions
Timezone conversion
Intervals
34. BETWEEN WITH INTERVALS
Current date and time
Revision

Instruction

Fine! The query worked this time.

Intervals are typically used with BETWEEN to select facts from a given day, month, year etc. Take a look:

SELECT id
FROM aircraft
WHERE produced BETWEEN '2010-01-01'
AND CAST('2010-01-01' AS date) + INTERVAL '1' YEAR;

The above query will look for aircraft produced in 2010. Note that we needed to use CAST when adding an interval.

Exercise

Show the id and the model for all the aircraft produced in 2014 and 2015.

Code editor

TableConsole