×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

More than one record in the same interval

More than one record in the same interval

More than one record in the same interval

(OP)
Hello,

I have a table that defines wich person is using a DB user at a time:

DB_USER ID_NAME LOGIN LOGOFF
USER1 Ana 27-10-2012 18:10:05 27-10-2012 18:18:05
USER1 John 27-10-2012 18:18:06 27-10-2012 18:28:05
USER1 Greg 27-10-2012 18:20:09 27-10-2012 18:25:05


How can I find out if more than one person was using the same DB user at that interval of time? I know that in this example it should return the following:

DB_USER ID_NAME Date
USER1 John 27-10-2012
USER1 Greg 27-10-2012

Can you help me?
Thanks

RE: More than one record in the same interval

If you have workspace manager available to you check out the WM_PERIOD and WM_OVERAPS - and a few other WM_*
funtions too - which will help you solve this. Alternatively there is an undocumented Oracle SQL function called overlaps which again may be of use, although I wouldn't base any production tasks on it.


In order to understand recursion, you must first understand recursion.

RE: More than one record in the same interval

Ana,

Given your data:

CODE

select A.DB_USER a_db_user
      ,A.ID_NAME a_id_name
      ,to_char(A.LOGIN,'dd-MON-yyyy hh24:mi:ss') a_login
      ,to_char(A.LOGOFF,'dd-MON-yyyy hh24:mi:ss') a_logoff
  from logins a
/

A_DB_USER A_ID_NAME A_LOGIN              A_LOGOFF
--------- --------- -------------------- --------------------
USER1     Ana       27-OCT-2012 18:10:05 27-OCT-2012 18:18:05
USER1     John      27-OCT-2012 18:18:06 27-OCT-2012 18:28:05
USER1     Greg      27-OCT-2012 18:20:09 27-OCT-2012 18:25:05

3 rows selected. 

...there are several ways you can solve your need. Here is one way:

CODE

SELECT A.DB_USER a_db_user
      ,A.ID_NAME a_id_name
      ,to_char(A.LOGIN,'dd-MON-yyyy hh24:mi:ss') a_login
      ,to_char(A.LOGOFF,'dd-MON-yyyy hh24:mi:ss') a_logoff
      ,b.DB_USER b_db_user
      ,b.ID_NAME b_id_name
      ,to_char(b.LOGIN,'dd-MON-yyyy hh24:mi:ss')  b_login
      ,to_char(b.LOGOFF,'dd-MON-yyyy hh24:mi:ss') b_logoff
  from (SELECT DB_USER, ID_NAME, LOGIN, LOGOFF
          FROM LOGINS) A
      ,(SELECT DB_USER, ID_NAME, LOGIN, LOGOFF
          FROM LOGINS) b
 WHERE a.db_user = b.db_user
   and a.id_name <> b.id_name
   and (a.login between b.login and b.logoff
        or
        a.logoff between b.login and b.logoff)
/

A_DB_USER A_ID_NAME A_LOGIN              A_LOGOFF             B_DB_USER B_ID_NAME B_LOGIN              B_LOGOFF
--------- --------- -------------------- -------------------- --------- --------- -------------------- --------------------
USER1     Greg      27-OCT-2012 18:20:09 27-OCT-2012 18:25:05 USER1     John      27-OCT-2012 18:18:06 27-OCT-2012 18:28:05

1 row selected. 

Let us know if this is satisfactory and if you have additional questions.

santaMufasa
(aka Dave of Sandy, Utah, USA)
“People may forget what you say, but they will never forget how you made them feel."

RE: More than one record in the same interval

(OP)
Hello,

It worked. Thanks for all your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close