pl/sql Compare with previous row <p>The goal is to combine Time_a within 10 min interval that has same ID. And group the ID.</p> <pre><code>ID Time_a -&gt; ID ------------ ---------- 1 12:10:00 1 1 12:15:00 2 1 12:20:00 2 2 12:25:00 2 12:35:00 2 02:00:00 </code></pre> <p>It became two '2' because time interval between row5 and row6 is more than 10 min. I was able to combine within 10-min difference, but it doesn't distinguish ID.</p> <pre><code>select ID from( select id, Time_a, min(time) OVER (order by id, time rows between 1 preceding and 1 preceding) prev_t_stamp from dual ) where abs(Time_a-prev_t_stamp)&gt;10/1440 </code></pre>