dbTalk Databases Forums  

SQL for this query

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss SQL for this query in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hilljm1974@gmail.com
 
Posts: n/a

Default SQL for this query - 11-15-2011 , 10:28 AM






I have a sessions table like the following:

SID UserID TimeIn TimeOut
1 10 Aug-10-2011 11:30:45 Aug-10-2011 11:32:13
2 11 Aug-10-2011 11:30:55 Aug-10-2011 11:31:01
3 54 Aug-10-2011 11:31:02 Aug-10-2011 11:33:48
4 21 Aug-10-2011 11:34:11 Aug-10-2011 11:35:19

I need a query to return the count of active users for each records
time range, such that:

for SID 1, the count would be 3 because there are 3 records whose
TimeIn <= SID 1's TimeOut
for SID 2, the count would be 2 because there are 2 records whose
TimeIn <= SID 2's TimeOut

etc.

Reply With Quote
  #2  
Old   
joel garry
 
Posts: n/a

Default Re: SQL for this query - 11-15-2011 , 10:45 AM






On Nov 15, 8:28*am, "hilljm1... (AT) gmail (DOT) com" <hilljm1... (AT) gmail (DOT) com>
wrote:
Quote:
I have a sessions table like the following:

SID UserID * * * * * TimeIn * * * * * * * * ** * * * TimeOut
1 * * *10 * * *Aug-10-2011 11:30:45 * * * * * *Aug-10-2011 11:32:13
2 * * *11 * * *Aug-10-2011 11:30:55 * * * * * *Aug-10-2011 11:31:01
3 * * *54 * * *Aug-10-2011 11:31:02 * * * * * *Aug-10-2011 11:33:48
4 * * *21 * * *Aug-10-2011 11:34:11 * * * * * *Aug-10-2011 11:35:19

I need a query to return the count of active users for each records
time range, such that:

for SID 1, the count would be 3 because there are 3 records whose
TimeIn <= SID 1's TimeOut
for SID 2, the count would be 2 because there are 2 records whose
TimeIn <= SID 2's TimeOut

etc.
Some people may answer this, but in general, you will get a better
response for this kind of question if you provide table creation and
data loading statements. That way, people can start from the same
place you are, and play around until they get what you say you want.
This also helps reduce ambiguity with a very small data set. If you
show what you tried, that might help some people think you aren't just
asking for people to do your work for you.

jg
--
@home.com is bogus.
Robertson doesn't get it, again: http://www.signonsandiego.com/news/2...ivacy-history/

Reply With Quote
  #3  
Old   
Mark D Powell
 
Posts: n/a

Default Re: SQL for this query - 11-16-2011 , 09:09 AM



On Nov 15, 11:45*am, joel garry <joel-ga... (AT) home (DOT) com> wrote:
Quote:
On Nov 15, 8:28*am, "hilljm1... (AT) gmail (DOT) com" <hilljm1... (AT) gmail (DOT) com
wrote:





I have a sessions table like the following:

SID UserID * * * * * TimeIn * * * * * * * * * * * * * TimeOut
1 * * *10 * * *Aug-10-2011 11:30:45 * * * * * *Aug-10-2011 11:32:13
2 * * *11 * * *Aug-10-2011 11:30:55 * * * * * *Aug-10-2011 11:31:01
3 * * *54 * * *Aug-10-2011 11:31:02 * * * * * *Aug-10-2011 11:33:48
4 * * *21 * * *Aug-10-2011 11:34:11 * * * * * *Aug-10-2011 11:35:19

I need a query to return the count of active users for each records
time range, such that:

for SID 1, the count would be 3 because there are 3 records whose
TimeIn <= SID 1's TimeOut
for SID 2, the count would be 2 because there are 2 records whose
TimeIn <= SID 2's TimeOut

etc.

Some people may answer this, but in general, you will get a better
response for this kind of question if you provide table creation and
data loading statements. *That way, people can start from the same
place you are, and play around until they get what you say you want.
This also helps reduce ambiguity with a very small data set. *If you
show what you tried, that might help some people think you aren't just
asking for people to do your work for you.

jg
--
@home.com is bogus.
Robertson doesn't get it, again:http://www.signonsandiego.com/news/2...vacy-history/- Hide quoted text -

- Show quoted text -
1974, I second what Joel said. Also I cannot tell from the sample but
are your sure that the Time-In does not need to be accounted for when
performing the count. Just counting sessions that have a Time-In less
that another session's Time-Out seems pretty useless unless the data
is limited in the duration of time being covered to begin with.

HTH -- Mark D Powell --

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.