【发布时间】:2016-10-03 21:49:34
【问题描述】:
我正在尝试按升序排列日期序列中的所有缺失日期。如何在不使用任何函数或 udfs 的情况下使用简单的 sql 来完成。
Input :-
2016-09-01
2016-09-02
2016-09-05
2016-09-10
输出:-
2016-09-03
2016-09-04
2016-09-06
2016-09-07
2016-09-08
2016-09-09
我尝试了什么?
select start, stop
from
(
select m.x + 1 as start,
(select min(x) - 1 from X as x where x.x > m.x) as stop
from X as m
left outer join X as r
on m.x = r.x - 1
where r.x is null
) as x
where stop is not null;
【问题讨论】:
-
如果您标记正在使用的 dbms 并显示您的尝试,这将有所帮助。
-
我正在尝试使用整数解决它,然后跳转到日期。
-
你的数据库支持递归公用表表达式吗?
-
支持 CTE
-
对我来说似乎没有错过日期
标签: sql amazon-redshift paraccel