Teradata Interval功能

时间:2017-12-30 04:15:31

标签: sql function date teradata intervals

Teradata在使用内置函数INTERVAL时失败,当与MONTH规范一起用于在2月份推导日期时

SELECT Cast('2017-12-29' as date) - INTERVAL '10' MONTH;
SELECT Cast('2017-12-30' as date) - INTERVAL '10' MONTH;
SELECT Cast('2017-12-31' as date) - INTERVAL '10' MONTH;
SELECT Cast('2018-12-29' as date) - INTERVAL '10' MONTH;
SELECT Cast('2018-12-30' as date) - INTERVAL '10' MONTH;
SELECT Cast('2018-12-31' as date) - INTERVAL '10' MONTH;
SELECT Cast('2019-12-29' as date) - INTERVAL '10' MONTH;
SELECT Cast('2019-12-30' as date) - INTERVAL '10' MONTH;
SELECT Cast('2019-12-31' as date) - INTERVAL '10' MONTH;
SELECT Cast('2020-12-30' as date) - INTERVAL '10' MONTH;
SELECT Cast('2020-12-31' as date) - INTERVAL '10' MONTH;

SELECT CURRENT_DATE - INTERVAL '10' MONTH;-- << If current date is 29,30,31 day of December month Non leap year and 30,31 day of December month leap year>>

1 个答案:

答案 0 :(得分:1)

使用Add_Months函数代替Interval函数..

SELECT ADD_MONTHS(CAST ('2017-12-29' AS DATE),-10);
SELECT ADD_MONTHS(CURRENT_DATE,-10); -- << If current date is 29,30,31 day of December month Non leap year and 30,31 day of December month leap year>>