Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在做路径分析,我需要查看一页通向何处。如何编写一个查询来获取所有具有特定值的先前记录的记录。
例如:
col1 timestamp a 1 b 2 a 3 c 4 b 5 e 6
我只想返回 c 和 b
我正在尝试使用窗口函数来执行此操作,但我没有使用它们的经验并且完全失败了:-(
感谢您的回答!
您将使用该lag()功能。. . 和一个子查询:
lag()
select t.* from (select t.*, lag(col1) over (order by timestamp) as prev_col1 from t ) t where prev_col1 = 'a';
Oracle 的 Lead 和 Lag 功能将帮助您实现预期的结果。
例子