17.00 - 17.05 - Example - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Date and Time Functions and Expressions

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
17.05
Release Date
June 2020
Content Type
Programming Reference
Publication ID
B035-1211-170K
Language
English (United States)

LDIFF is used to find the left difference of the first Period expression with the second Period expression.

SELECT ename, period2 LDIFF period1 FROM employee;

Assume the query is executed on the following employee table where period1 and period2 are PERIOD(DATE) columns:

ename   period1                        period2
-----   ----------------------------   ----------------------------
Adams   ('2005-02-03', '2006-02-03')   ('2005-02-03', '2006-02-03')
Mary    ('2005-04-02', '2006-01-03')   ('2005-02-03', '2006-02-03')
Jones   ('2004-01-02', '2004-03-05')   ('2002-03-05', '2004-10-07')
Randy   ('2006-01-02', '2007-03-05')   ('2004-03-07', '2005-10-07')
Simon   ?                              ('2005-02-03', '2005-07-27')

The result is:

ename   (period2 LDIFF period1)
-----   ----------------------------
Adams   ?
Mary    ('2005-02-03', '2005-04-02')
Jones   ('2002-03-05', '2004-01-02')
Randy   ?
Simon   ?