teradata查询中前后的区别是什么

时间:2015-02-08 16:36:37

标签: sql teradata

我很困惑为什么我们使用这个min函数。我无法理解下面的代码片段如何工作。请指导

COALESCE( min((start_Date)) OVER (partition by Seq_id  ORDER BY start_Date rows between 1 following and 1 following),cast( '9999-12-31 00:00:00' as timestamp(6))  end_Date FROM table.test1

2 个答案:

答案 0 :(得分:2)

这是您的查询:

SELECT COALESCE(min((start_Date)) OVER (partition by Seq_id 
                                        ORDER BY start_Date
                                        rows between 1 following and 1 following
                                      ),
         cast( '9999-12-31 00:00:00' as timestamp(6))
        ) as end_Date
FROM table.test1

此查询正在执行;

SELECT COALESCE(LEAD(Start_Date) OVER (PARTITION BY seq_id ORDER BY start_date),
                cast( '9999-12-31 00:00:00' as timestamp(6))
               ) as end_Date

也就是说,它是从Start_Date定义的“下一行”中获取日期值。

我认为使用此构造是因为(某些版本)Teradata不支持LEAD()

答案 1 :(得分:0)

你可以在Teradata窗口函数,Preceding和Preceding之间的行之间找到很好的解释: http://pauldhip.blogspot.dk/2015/04/window-function-rows-between-preceding.html