Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle-Advanced SQL-question

Re: Oracle-Advanced SQL-question

From: AK <AK_TIREDOFSPAM_at_hotmail.COM>
Date: 6 Jun 2005 12:45:02 -0700
Message-ID: <1118087102.503676.238640@g47g2000cwa.googlegroups.com>


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 Received on Mon Jun 06 2005 - 14:45:02 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US