0
我試圖以某種方式獲取數據組織。這裏是我想要做的從Redshift獲取數據clubbed
我有紅移表,從中我們正在試圖讓下面的輸出
表:富
e1 | c1 | c2 1 | 1 | 2 1 | 3 | 4 1 | 5 | 7 1 | 9 | 15 2 | 3 | 4 2 | 7 | 8
我們正試圖俱樂部所有行,其中前一行C2下一行C1之間差值小於1
所需的輸出
e1 | c1 | c2 1 | 1 | 7 1 | 9 | 15 2 | 3 | 4 2 | 7 | 8
電流輸出
e1 | c1 | c2 1 | 1 | 4 1 | 3 | 7 2 | 3 | 4 2 | 7 | 8
我試過做CTE。這是我正在處理的查詢。我得到的是隔離的,或與
CTE結果:
with es as(
select *
from foo
where e1 not in (SELECT t1.e1
FROM foo as t1
inner join foo as t2
on t1.e1=t2.e1 and (t2.c1-t1.c2)=1)
union all
SELECT t1.e1
,t1.c1
,isnull(t2.c2, t1.c2) as c2
FROM foo as t1
inner join foo as t2
on t1.e1=t2.e1 and (t2.c1-t1.c2)=1
)
select * from es
where e1 is not null
有人可以幫我嗎?
答案並不完整,但我理解了這種方法。謝謝@ denismo –