Example - Analytics Database - Teradata Vantage

SQL Date and Time Functions and Expressions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-10-30
dita:mapPath
cpk1628111786971.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
pxz1544241488545
lifecycle
latest
Product Category
Teradata Vantage™

Assume that in the employee table, created by the following CREATE TABLE statement, jobdur1 and jobdur2 are derived period columns.

CREATE TABLE employee (
   eid INTEGER NOT NULL, 
   name VARCHAR(100) NOT NULL,
   deptno INTEGER NOT NULL,
   jobst1 DATE NOT NULL,
   jobend1   DATE NOT NULL,
   PERIOD FOR jobdur1(jobst1, jobend1),
   jobst2 DATE NOT NULL,
   jobend2   DATE NOT NULL,
   PERIOD FOR jobdur2(jobst2, jobend2)
   ) PRIMARY INDEX(eid);
EID Name Dept No JobSt1 JobEnd1 JobSt2 JobEnd2
1 Tom 101 DATE'2001-01-01' DATE'2004-01-01' DATE'2005-01-01' DATE'2006-01-01'
2 Rick 201 DATE'2005-01-01' DATE'2006-01-01' DATE'2001-01-01' DATE'2004-01-01'
3 Joo 301 DATE'2005-01-01' DATE'2006-01-01' DATE'2006-01-01' DATE'2007-01-01'
4 Tam 401 DATE'2001-01-01' DATE'2006-01-01' DATE'2002-01-01' DATE'2004-01-01'
5 Pat 501 DATE'2005-01-01' DATE'2007-01-01' DATE'2006-01-01' DATE'2008-01-01'
6 Jack 601 DATE'2005-01-01' DATE'2007-01-01' DATE'2007-01-01' DATE'2008-01-01'
7 Yu 701 DATE'2005-01-01' DATE'2007-01-01' DATE'2004-01-01' DATE'2005-01-01'
8 Tim 801 DATE'2005-01-01' DATE'2007-01-01' DATE'2005-01-01' DATE'2007-01-01'

In the following SQL statement, OVERLAPS is used with derived period columns of the employee table:

SELECT eid, name, jobst1, jobend1, jobst2, jobend2 
FROM employee 
WHERE jobdur1 OVERLAPS jobdur2;

The result is:

EID Name Dept No JobSt1 JobEnd1 JobSt2 JobEnd2
4 Tam 401 DATE'2001-01-01' DATE'2006-01-01' DATE'2002-01-01' DATE'2004-01-01'
5 Pat 501 DATE'2005-01-01' DATE'2007-01-01' DATE'2006-01-01' DATE'2008-01-01'
8 Tim 801 DATE'2005-01-01' DATE'2007-01-01' DATE'2005-01-01' DATE'2007-01-01'