![](/img/trans.png)
[英]Is there a way to return all records where the next record on a specific column has a value from previous record + 1?
[英]HIVE: Get all records where preceding record (by timestamp) is a specific value
我正在進行路徑分析,我需要查看一頁頁面的位置。 如何編寫查詢,以獲取具有先前特定值記錄的所有記錄。
例如:
col1 timestamp
a 1
b 2
a 3
c 4
b 5
e 6
我只想返回c和b
我正在嘗試使用窗口函數來執行此操作,但是我沒有使用它們的經驗,並且完全失敗了:-(
感謝您的回答!
您將使用lag()
函數。 。 。 和一個子查詢:
select t.*
from (select t.*, lag(col1) over (order by timestamp) as prev_col1
from t
) t
where prev_col1 = 'a';
Oracle的領先和落后功能將幫助您實現預期的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.