Here's one solution:<br /><br />create temp sequence tsec;<br />create temp table ttab as select nextval('tsec'), *
from(select * from events where event_type='a' order by timestamp desc) as troz;<br />select ttab.*,
ttab2.timestamp-ttab.timestampfrom ttab join ttab as ttab2 on ttab2.nextval = ttab.nextval+1;<br /><br />This works,
butseems a very messy way to accomplish somehting quite simple.<br /><br /><br /><div class="gmail_quote">On Wed, Oct
29,2008 at 11:01 AM, Murray Long <span dir="ltr"><<a
href="mailto:murray@skyrove.com">murray@skyrove.com</a>></span>wrote:<br /><blockquote class="gmail_quote"
style="border-left:1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I'm relatively new to
SQL,and am frequently running into the same problem, How do I compare different rows in a result?<br /><br />for
example:<br/>If I have a table of events consisting of a time stamp and the event type:<br /><br />timestamp,
event_type<br/>12:00 a<br />12:10 b<br />12:20 a<br />...<br /><br
/>I'dlike to be able to select all the 'a' type events and calculate the time since the previous 'a' event, to get:<br
/>timestamp, event_type, time_since_last<br /> 12:00 a 0:20<br />
12:20 a NULL<br /><br />What's the best way to to accomplish this? <br /><br
/><br/>Thanks in advance,<br /><font color="#888888">Murray<br /><br /><br /><br /></font></blockquote></div><br />