×
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

Jobs

Trying to do a count on logged in users

Trying to do a count on logged in users

Trying to do a count on logged in users

(OP)
I am trying to build a query where I can get a count of logged in users. There is a field called eventtype. If it is set to one, then the user is logged in. If it is set to seven, then they are logged out. There are a number of other eventtypes that I can ignore. There is a datetime stamp for each eventtype (see sample data below). I might be able to do this in MS-SQL, but the database is Informix which I am not as well versed in. Any assistance would be appreciated.

Sample Data
UserID DateTime Eventtype
11604 6/27/2016 3.05.53 PM 1 login
11604 6/27/2016 3.05.53 PM 2
11604 6/27/2016 3.06.21 PM 3
11604 6/27/2016 3.07.51 PM 4
11604 6/27/2016 3.08.01 PM 5
11604 6/27/2016 3.11.59 PM 6
11604 6/27/2016 3.16.45 PM 3
11604 6/27/2016 3.20.53 PM 7 logout
11604 6/27/2016 3.25.53 PM 1 login
...etc.

RE: Trying to do a count on logged in users

(OP)
I found a solution. It is neither elegant or fast.

select
sum(logged_in) as loggedIn,
sum(not_ready) as notReady,
sum(ready) as Ready,
sum(reserved) as Reserved,
sum(talking) as Talking,
sum(work) as Work

from (select

agentid,
case when eventtype = 2 then count(distinct agentid) end as not_ready,
case when eventtype = 3 then count(distinct agentid) end as ready,
case when eventtype = 4 then count(distinct agentid) end as reserved,
case when eventtype = 5 then count(distinct agentid) end as talking,
case when eventtype = 6 then count(distinct agentid) end as work,
case when eventtype <> 7 then count(distinct agentid) end as logged_in

from agentstatedetail asd
where eventdatetime> today
and eventdatetime = (select max(eventdatetime) from agentstatedetail where asd.agentid = agentstatedetail.agentid)
group by agentid, eventtype
order by agentid, max(eventdatetime) desc)

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