By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

Counting users online with last hour

P: n/a
Hi,

I have a log table which contains the fields log_time (DATETIME) and
session_id (VARCHAR). Using these 2 columns I want to be able to SELECT the
number of users who have been online during the past hour. Getting the
number of rows logged in the last hour is easy but I can't work out how to
only count distinct session_id entries.

Thanks,

Mark
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Not to worry. I think I've worked it out:

SELECT COUNT( DISTINCT (
session_id
) )
FROM log
WHERE DATE_SUB( CURDATE( ) , INTERVAL 30
DAY ) <= log_date

Mark

"Mark Jerzykowski" <ma**************@ntlworld.com> wrote in message
news:Ge***************@newsfe2-gui.ntli.net...
Hi,

I have a log table which contains the fields log_time (DATETIME) and
session_id (VARCHAR). Using these 2 columns I want to be able to SELECT the number of users who have been online during the past hour. Getting the
number of rows logged in the last hour is easy but I can't work out how to
only count distinct session_id entries.

Thanks,

Mark
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004
Jul 20 '05 #2

P: n/a
Mark Jerzykowski wrote:
I have a log table which contains the fields log_time (DATETIME) and
session_id (VARCHAR). Using these 2 columns I want to be able to SELECT the
number of users who have been online during the past hour. Getting the
number of rows logged in the last hour is easy but I can't work out how to
only count distinct session_id entries.


Mark J. posted one method, but here is another for comparison:

SELECT MAX(log_time), session_id
FROM myTable
WHERE log_time > now() - interval 60 minute
GROUP BY session_id;

Regards,
Bill K.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.