我在Vertica中遇到了一个与填写不存在的日期相关的问题。我在网上看到过一些解决方案,人们建议创建一个日程表。这里有一个来自堆栈溢出的MYSQL问题。
有没有一种方法可以使用另一个表中的min()和max()可用日期,只使用Vertica支持的SQL而不使用过程?到目前为止,我遇到的大多数解决方案都是基于T-SQL的,日期是使用过程生成的。不幸的是,我的Vertica并没有那么多的PL/SQL或T-SQL能力。但是有一些分析函数,我怀疑它们可能能够解决我的问题。
发布于 2013-06-18 07:46:11
正如我在问题中提到的,我现在回答这个问题,因为我已经找到了使用开始和结束日期创建日历表或视图的问题的解决方案。
CREATE table mytest.calendar
(
date DATE primary key
);将边界日期插入日历表格中(所需表格中的最小和最大日期)。
Insert into mytest.calendar (select min(date) from mytest.benchmarks);
Insert into mytest.calendar (select max(date) from mytest.benchmarks);现在,要生成中间日期,请执行以下操作:
SELECT CAST(slice_time AS DATE) date
FROM mytest.calendar mtc
TIMESERIES slice_time as '1 day'
OVER (ORDER BY CAST(mtc.date as TIMESTAMP));您可以将其单独用作表:
SELECT date from
(SELECT CAST(slice_time AS DATE) date
FROM mytest.calendar mtc
TIMESERIES slice_time as '1 day'
OVER (ORDER BY CAST(mtc.date as TIMESTAMP))) calendar
where mytest.isBusinessDay(date) = 't';
SELECT date
FROM
(SELECT date
FROM
(SELECT CAST(slice_time AS DATE) date
FROM mytest.calendar mtc
TIMESERIES slice_time as '1 day'
OVER (ORDER BY CAST(mtc.date as TIMESTAMP))
) calendar
WHERE mytest.isBusinessDay(date) = 't') calendar;我有从开始日期(来自基准测试表的min(date) )到结束日期(即max(date))的日期列表。
https://stackoverflow.com/questions/17155805
复制相似问题