SQL for this query

From: <hilljm1974_at_gmail.com>
Date: Tue, 15 Nov 2011 08:28:31 -0800 (PST)
Message-ID: <8b8adbb0-1ec8-47c2-9863-a69e71a80982_at_o14g2000yqh.googlegroups.com>



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. Received on Tue Nov 15 2011 - 10:28:31 CST

Original text of this message