Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!drn.maxwell.syr.edu!news.maxwell.syr.edu!postnews.google.com!g47g2000cwa.googlegroups.com!not-for-mail
From: "AK" <AK_TIREDOFSPAM@hotmail.COM>
Newsgroups: comp.databases.oracle.misc
Subject: Re: Oracle-Advanced SQL-question
Date: 6 Jun 2005 12:45:02 -0700
Organization: http://groups.google.com
Lines: 26
Message-ID: <1118087102.503676.238640@g47g2000cwa.googlegroups.com>
References: <1118062535.89@user.newsoffice.de>
   <1118081649.58@user.newsoffice.de>
NNTP-Posting-Host: 205.156.188.254
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1118087109 10605 127.0.0.1 (6 Jun 2005 19:45:09 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 6 Jun 2005 19:45:09 +0000 (UTC)
In-Reply-To: <1118081649.58@user.newsoffice.de>
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: g47g2000cwa.googlegroups.com; posting-host=205.156.188.254;
   posting-account=dcyjXg0AAAAAr7KEmYS5ttp6D-QeNceH
Xref: dp-news.maxwell.syr.edu comp.databases.oracle.misc:119670

One more thing: you don't have to repeat one and the same expression
twice, you can use an inline view aka table expression instead:

select CIDUSER, CTIMESTAMP, logout_time, round((logout_time -
CTIMESTAMP)*24*60)
from(
select CIDUSER, CTIMESTAMP,
(select min(CTIMESTAMP) from event e1 where e1.CSUBJECT='logout'
and e1.CIDUSER = event.CIDUSER and e1.CTIMESTAMP > event.CTIMESTAMP
and not exists(select * from event e2 where e1.CIDUSER = e2.CIDUSER
and event.CTIMESTAMP < e2.CTIMESTAMP and e2.CTIMESTAMP < e1.CTIMESTAMP
)
) logout_time
from event where CSUBJECT='login')iv
CIDUSER CTIMESTAMP            LOGOUT_TIME           SESSION_DURATION
------- --------------------- --------------------- ----------------
      1 12/10/2004
      1 12/11/2004
      1 12/12/2004            12/14/2004                        2880
      1 12/15/2004
      1 12/16/2004            12/17/2004                        1440
      1 12/19/2004
6 rows selected
 
this way your code is easier to read and more maintainable

