我一直在工作,看看Oracle超前和滞后函数的等效函数。
oracle领导看起来像
LEAD(col1.date,1,ADD_MONTHS(col1.DATE,12))
OVER(Partition By tab.a,tab.b,tab.c Order By tab.a)-1 END_DATE
LAG(col1.DATE + 7,1,col1.DATE-1)
OVER(partition by tab.a,tab.b Order By tab.b) LAG_DATE
更好的主意
答案 0 :(得分:9)
我相信您可以将以下SQL作为基础并进行修改以满足您的需求:
SELECT CALENDAR_DATE
, MAX(CALENDAR_DATE)
OVER(PARTITION BY 1 ORDER BY CALENDAR_DATE
ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS Lag_ --Yesterday
, MIN(CALENDAR_DATE)
OVER(PARTITION BY 1 ORDER BY CALENDAR_DATE
ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING) AS Lead_ --Tomorrow
FROM SysCalendar.CALENDAR
WHERE year_of_calendar = 2011
AND month_of_year = 11
如果之前或之后没有记录,则返回NULL,并且可以根据需要使用COALESCE进行寻址。
编辑在Teradata 16.00中引入了LAG / LEAD功能。